1 // Copyright Louis Dionne 2013-2017 2 // Distributed under the Boost Software License, Version 1.0. 3 // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) 4 5 #include <boost/hana/assert.hpp> 6 #include <boost/hana/not.hpp> 7 #include <boost/hana/type.hpp> 8 9 #include <string> 10 #include <vector> 11 namespace hana = boost::hana; 12 13 main()14int main() { 15 // Checking for a member 16 struct Person { std::string name; }; 17 auto has_name = hana::is_valid([](auto&& p) -> decltype((void)p.name) { }); 18 19 Person joe{"Joe"}; 20 static_assert(has_name(joe), ""); 21 static_assert(!has_name(1), ""); 22 23 24 // Checking for a nested type 25 auto has_value_type = hana::is_valid([](auto t) -> hana::type< 26 typename decltype(t)::type::value_type 27 > { }); 28 29 static_assert(has_value_type(hana::type_c<std::vector<int>>), ""); 30 static_assert(!has_value_type(hana::type_c<Person>), ""); 31 } 32