is_converter.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright (c) 2009-2016 Vladimir Batov.
  2. // Use, modification and distribution are subject to the Boost Software License,
  3. // Version 1.0. See http://www.boost.org/LICENSE_1_0.txt.
  4. #ifndef BOOST_CONVERT_IS_CONVERTER_HPP
  5. #define BOOST_CONVERT_IS_CONVERTER_HPP
  6. #include <boost/convert/detail/config.hpp>
  7. #include <boost/convert/detail/is_callable.hpp>
  8. #include <boost/utility/enable_if.hpp>
  9. #include <boost/type_traits.hpp>
  10. #include <boost/ref.hpp>
  11. namespace boost { namespace cnv
  12. {
  13. template<typename, typename, typename, typename =void>
  14. struct is_cnv { BOOST_STATIC_CONSTANT(bool, value = false); };
  15. template<typename Class, typename TypeIn, typename TypeOut>
  16. struct is_cnv<Class, TypeIn, TypeOut, typename enable_if<is_class<Class>, void>::type>
  17. {
  18. typedef typename ::boost::unwrap_reference<Class>::type class_type;
  19. typedef void signature_type(TypeIn const&, optional<TypeOut>&);
  20. BOOST_DECLARE_IS_CALLABLE(is_callable, operator());
  21. BOOST_STATIC_CONSTANT(bool, value = (is_callable<class_type, signature_type>::value));
  22. };
  23. template<typename Function, typename TypeIn, typename TypeOut>
  24. struct is_cnv<Function, TypeIn, TypeOut,
  25. typename enable_if_c<is_function<Function>::value && function_types::function_arity<Function>::value == 2,
  26. void>::type>
  27. {
  28. typedef TypeIn in_type;
  29. typedef optional<TypeOut>& out_type;
  30. typedef typename function_traits<Function>::arg1_type func_in_type;
  31. typedef typename function_traits<Function>::arg2_type func_out_type;
  32. BOOST_STATIC_CONSTANT(bool, in_good = (is_convertible<in_type, func_in_type>::value));
  33. BOOST_STATIC_CONSTANT(bool, out_good = (is_same<out_type, func_out_type>::value));
  34. BOOST_STATIC_CONSTANT(bool, value = (in_good && out_good));
  35. };
  36. }}
  37. #endif // BOOST_CONVERT_IS_CONVERTER_HPP