diff options
Diffstat (limited to 'src/boost/libs/hana/example/type/is_valid.cpp')
-rw-r--r-- | src/boost/libs/hana/example/type/is_valid.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/boost/libs/hana/example/type/is_valid.cpp b/src/boost/libs/hana/example/type/is_valid.cpp new file mode 100644 index 000000000..a683e78f1 --- /dev/null +++ b/src/boost/libs/hana/example/type/is_valid.cpp @@ -0,0 +1,31 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/assert.hpp> +#include <boost/hana/not.hpp> +#include <boost/hana/type.hpp> + +#include <string> +#include <vector> +namespace hana = boost::hana; + + +int main() { + // Checking for a member + struct Person { std::string name; }; + auto has_name = hana::is_valid([](auto&& p) -> decltype((void)p.name) { }); + + Person joe{"Joe"}; + static_assert(has_name(joe), ""); + static_assert(!has_name(1), ""); + + + // Checking for a nested type + auto has_value_type = hana::is_valid([](auto t) -> hana::type< + typename decltype(t)::type::value_type + > { }); + + static_assert(has_value_type(hana::type_c<std::vector<int>>), ""); + static_assert(!has_value_type(hana::type_c<Person>), ""); +} |