is_path.hpp 1.2 KB

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