is_path.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. //
  2. // Copyright (c) 2020 Alexander Grund
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. #ifndef BOOST_NOWIDE_DETAIL_IS_PATH_HPP_INCLUDED
  9. #define BOOST_NOWIDE_DETAIL_IS_PATH_HPP_INCLUDED
  10. #include <type_traits>
  11. namespace boost {
  12. namespace nowide {
  13. namespace detail {
  14. /// Trait to heuristically check for a *\::filesystem::path
  15. /// Done by checking for make_preferred and filename member functions with correct signature
  16. template<typename T>
  17. struct is_path
  18. {
  19. template<typename U, U& (U::*)(), U (U::*)() const>
  20. struct Check;
  21. template<typename U>
  22. static std::true_type test(Check<U, &U::make_preferred, &U::filename>*);
  23. template<typename U>
  24. static std::false_type test(...);
  25. static constexpr bool value = decltype(test<T>(0))::value;
  26. };
  27. /// SFINAE trait which has a member "type = Result" if the Path is a *\::filesystem::path
  28. template<typename Path, typename Result>
  29. using enable_if_path_t = typename std::enable_if<is_path<Path>::value, Result>::type;
  30. } // namespace detail
  31. } // namespace nowide
  32. } // namespace boost
  33. #endif