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

Description

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.

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

Example

// 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 <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)
result.push_back(to<To>(x));
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>>{}, "");
}
Defines macros to perform different kinds of assertions.
Defines boost::hana::to and related utilities.
Defines boost::hana::when and boost::hana::when_valid.
#define BOOST_HANA_RUNTIME_CHECK(...)
Equivalent to BOOST_HANA_RUNTIME_ASSERT, but not influenced by the BOOST_HANA_CONFIG_DISABLE_ASSERTIO...
Definition: assert.hpp:209
constexpr auto to
Converts an object from one data type to another.
Definition: to.hpp:97
constexpr auto apply
Invokes a Callable with the given arguments.
Definition: apply.hpp:40
Namespace containing everything in the library.
Definition: accessors.hpp:20

Inherited by boost::hana::to_impl< T *, decltype(nullptr)>, boost::hana::to_impl< To, To >, boost::hana::to_impl< detail::copy_char_signedness< int >::type, char >, boost::hana::to_impl< detail::copy_char_signedness< long >::type, char >, boost::hana::to_impl< detail::copy_char_signedness< long long >::type, char >, boost::hana::to_impl< detail::copy_char_signedness< short >::type, char >, boost::hana::to_impl< double, float >, boost::hana::to_impl< long double, double >, boost::hana::to_impl< long double, float >, boost::hana::to_impl< signed int, signed char >, boost::hana::to_impl< signed int, signed short >, boost::hana::to_impl< signed long long, signed char >, boost::hana::to_impl< signed long long, signed int >, boost::hana::to_impl< signed long long, signed long >, boost::hana::to_impl< signed long long, signed short >, boost::hana::to_impl< signed long, signed char >, boost::hana::to_impl< signed long, signed int >, boost::hana::to_impl< signed long, signed short >, boost::hana::to_impl< signed short, signed char >, boost::hana::to_impl< unsigned int, unsigned char >, boost::hana::to_impl< unsigned int, unsigned short >, boost::hana::to_impl< unsigned long long, unsigned char >, boost::hana::to_impl< unsigned long long, unsigned int >, boost::hana::to_impl< unsigned long long, unsigned long >, boost::hana::to_impl< unsigned long long, unsigned short >, boost::hana::to_impl< unsigned long, unsigned char >, boost::hana::to_impl< unsigned long, unsigned int >, boost::hana::to_impl< unsigned long, unsigned short >, and boost::hana::to_impl< unsigned short, unsigned char >.