/* @copyright Louis Dionne 2014 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 #include #include #include using namespace boost::hana; //! [is_embedded] static_assert(is_embedded{}, ""); // int -> unsigned long could cause negative values to be lost static_assert(!is_embedded{}, ""); // similarly, float can't represent all the values of int static_assert(!is_embedded{}, ""); // OK, the conversion is lossless static_assert(is_embedded{}, ""); //! [is_embedded] //! [embedding] namespace boost { namespace hana { template struct to_impl, std::vector, when{}>> : embedding{}> { static std::vector apply(std::vector const& xs) { std::vector result; for (auto const& x: xs) result.push_back(to(x)); return result; } }; }} int main() { BOOST_HANA_RUNTIME_ASSERT( to>(std::vector{1.1, 2.2, 3.3}) == std::vector{1, 2, 3} ); static_assert(!is_embedded, std::vector>{}, ""); } //! [embedding]