Boost.Hana  1.0.1
Your standard library for metaprogramming
boost::hana::embedding< bool > Struct Template Reference


template<bool = true>
struct boost::hana::embedding< bool >

Marks a conversion between data types as being an embedding.

To mark a conversion between two data types To and From as an embedding, simply use embedding<true> (or simply embedding<>) as a base class of the corresponding to_impl specialization. If a to_impl specialization does not inherit embedding<true> or embedding<>, then it is not considered an embedding by the is_embedded metafunction.


The boolean template parameter is useful for marking a conversion as an embedding only when some condition is satisfied.


// Copyright Louis Dionne 2013-2016
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file or copy at
#include <vector>
namespace hana = boost::hana;
namespace boost { namespace hana {
template <typename To, typename From>
struct to_impl<std::vector<To>, std::vector<From>,
when<is_convertible<From, To>::value>>
: embedding<is_embedded<From, To>::value>
static std::vector<To> apply(std::vector<From> const& xs) {
std::vector<To> result;
for (auto const& x: xs)
return result;
int main() {
hana::to<std::vector<int>>(std::vector<float>{1.1, 2.2, 3.3})
std::vector<int>{1, 2, 3}
static_assert(!hana::is_embedded<std::vector<float>, std::vector<int>>{}, "");