strings.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* strings.h - Qt <-> std string conversions
  2. * Copyright (C) 2017 caryoscelus
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef STUDIO_UTIL_STRINGS_H_6E4FCAFB_9FD7_5EE6_9F44_8C71873BFB98
  18. #define STUDIO_UTIL_STRINGS_H_6E4FCAFB_9FD7_5EE6_9F44_8C71873BFB98
  19. #include <type_traits>
  20. #include <QString>
  21. namespace rainynite::util {
  22. template <typename S, typename T>
  23. T str(S&& s);
  24. // TODO: C++17 is_same_v
  25. template <typename S>
  26. std::enable_if_t<std::is_same<std::decay_t<S>,std::string>::value, QString>
  27. str(S&& s) {
  28. return QString::fromStdString(std::forward<S>(s));
  29. }
  30. template <typename S>
  31. std::enable_if_t<std::is_same<std::decay_t<S>,QString>::value, std::string>
  32. str(S&& s) {
  33. return s.toStdString();
  34. }
  35. } // namespace rainynite::util
  36. #endif