Boost.Hana  1.7.1
Your standard library for metaprogramming
boost::hana::is_default< Method, typename > Struct Template Reference

Description

template<typename Method, typename>
struct boost::hana::is_default< Method, typename >

Returns whether a tag-dispatched method implementation is a default implementation.

Given a tag-dispatched method implementation method_impl<T...>, is_default<method_impl<T...>> returns whether method_impl<T...> is a default implementation. Note that if there is no default implementation for the method, then is_default should not be used unless a static assertion saying that "the method is not implemented" is acceptable.

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 <algorithm>
#include <iterator>
#include <sstream>
#include <vector>
namespace hana = boost::hana;
// In the header defining the concept of a Printable
template <typename T>
struct print_impl : hana::default_ {
template <typename Stream, typename X>
static void apply(Stream& out, X const& x)
{ out << x; }
};
auto print = [](auto& stream, auto const& x) {
return print_impl<hana::tag_of_t<decltype(x)>>::apply(stream, x);
};
// In some other header
template <typename T>
struct print_impl<std::vector<T>> {
template <typename Stream>
static void apply(Stream& out, std::vector<T> const& xs) {
out << '[';
std::copy(begin(xs), end(xs), std::ostream_iterator<T>{out, ", "});
out << ']';
}
};
static_assert(hana::is_default<print_impl<int>>{}, "");
static_assert(!hana::is_default<print_impl<std::vector<int>>>{}, "");
int main() {
{
std::stringstream s;
print(s, std::vector<int>{1, 2, 3});
BOOST_HANA_RUNTIME_CHECK(s.str() == "[1, 2, 3, ]");
}
{
std::stringstream s;
print(s, "abcd");
BOOST_HANA_RUNTIME_CHECK(s.str() == "abcd");
}
}
Defines macros to perform different kinds of assertions.
Defines boost::hana::default_ and boost::hana::is_default.
Defines boost::hana::tag_of and boost::hana::tag_of_t.
#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
typename hana::tag_of< T >::type tag_of_t
Alias to tag_of<T>::type, provided for convenience.
Definition: tag_of.hpp:117
auto print
Returns a string representation of the given object.
Definition: printable.hpp:69
constexpr auto apply
Invokes a Callable with the given arguments.
Definition: apply.hpp:40
Namespace containing everything in the library.
Definition: accessors.hpp:20

Inherits std::false_type.