Boost.Hana  1.6.0
Your standard library for metaprogramming
boost::hana::default_ Struct Reference

Description

Mark a tag-dispatched method implementation as a default implementation.

When defining a new concept with tag-dispatched methods, it is sometimes possible to provide a default implementation for some method(s). Making default_ a base class of such a default implementation makes it possible to detect whether the method was dispatched to the default implementation afterwards.

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");
}
}

Inherited by boost::hana::accessors_impl< S, when< condition > >, boost::hana::adjust_if_impl< Fun, when< condition > >, boost::hana::adjust_impl< Fun, when< condition > >, boost::hana::all_impl< S, when< condition > >, boost::hana::all_of_impl< S, when< condition > >, boost::hana::and_impl< L, when< condition > >, boost::hana::any_impl< S, when< condition > >, boost::hana::any_of_impl< S, when< condition > >, boost::hana::ap_impl< A, when< condition > >, boost::hana::append_impl< M, when< condition > >, boost::hana::at_impl< It, when< condition > >, boost::hana::at_key_impl< S, when< condition > >, boost::hana::back_impl< It, when< condition > >, boost::hana::cartesian_product_impl< S, when< condition > >, boost::hana::chain_impl< M, when< condition > >, boost::hana::concat_impl< M, when< condition > >, boost::hana::contains_impl< S, when< condition > >, boost::hana::count_if_impl< T, when< condition > >, boost::hana::count_impl< T, when< condition > >, boost::hana::cycle_impl< M, when< condition > >, boost::hana::difference_impl< S, when< condition > >, boost::hana::div_impl< T, U, when< condition > >, boost::hana::drop_back_impl< S, when< condition > >, boost::hana::drop_front_exactly_impl< It, when< condition > >, boost::hana::drop_front_impl< It, when< condition > >, boost::hana::drop_while_impl< It, when< condition > >, boost::hana::duplicate_impl< W, when< condition > >, boost::hana::empty_impl< M, when< condition > >, boost::hana::equal_impl< T, U, when< condition > >, boost::hana::erase_key_impl< T, when< condition > >, boost::hana::eval_if_impl< L, when< condition > >, boost::hana::eval_impl< T, when< condition > >, boost::hana::extend_impl< W, when< condition > >, boost::hana::extract_impl< W, when< condition > >, boost::hana::fill_impl< Fun, when< condition > >, boost::hana::filter_impl< M, when< condition > >, boost::hana::find_if_impl< S, when< condition > >, boost::hana::find_impl< S, when< condition > >, boost::hana::first_impl< P, when< condition > >, boost::hana::flatten_impl< M, when< condition > >, boost::hana::fold_left_impl< T, when< condition > >, boost::hana::fold_right_impl< T, when< condition > >, boost::hana::for_each_impl< T, when< condition > >, boost::hana::front_impl< It, when< condition > >, boost::hana::greater_equal_impl< T, U, when< condition > >, boost::hana::greater_impl< T, U, when< condition > >, boost::hana::group_impl< S, when< condition > >, boost::hana::hash_impl< Tag, when< condition > >, boost::hana::if_impl< L, when< condition > >, boost::hana::insert_impl< T, when< condition > >, boost::hana::intersection_impl< S, when< condition > >, boost::hana::intersperse_impl< S, when< condition > >, boost::hana::is_disjoint_impl< S1, S2, when< condition > >, boost::hana::is_empty_impl< It, when< condition > >, boost::hana::is_subset_impl< S1, S2, when< condition > >, boost::hana::keys_impl< T, when< condition > >, boost::hana::length_impl< T, when< condition > >, boost::hana::less_equal_impl< T, U, when< condition > >, boost::hana::less_impl< T, U, when< condition > >, boost::hana::lexicographical_compare_impl< It, when< condition > >, boost::hana::lift_impl< A, when< condition > >, boost::hana::make_impl< Datatype, when< condition > >, boost::hana::max_impl< T, U, when< condition > >, boost::hana::maximum_impl< T, when< condition > >, boost::hana::maximum_pred_impl< T, when< condition > >, boost::hana::members_impl< S, when< condition > >, boost::hana::min_impl< T, U, when< condition > >, boost::hana::minimum_impl< T, when< condition > >, boost::hana::minimum_pred_impl< T, when< condition > >, boost::hana::minus_impl< T, T, when< condition > >, boost::hana::minus_impl< T, U, when< condition > >, boost::hana::mod_impl< T, U, when< condition > >, boost::hana::monadic_fold_left_impl< T, when< condition > >, boost::hana::monadic_fold_right_impl< T, when< condition > >, boost::hana::mult_impl< T, U, when< condition > >, boost::hana::negate_impl< T, when< condition > >, boost::hana::none_impl< S, when< condition > >, boost::hana::none_of_impl< S, when< condition > >, boost::hana::not_equal_impl< T, U, when< condition > >, boost::hana::not_impl< L, when< condition > >, boost::hana::one_impl< R, when< condition > >, boost::hana::or_impl< L, when< condition > >, boost::hana::partition_impl< S, when< condition > >, boost::hana::permutations_impl< S, when< condition > >, boost::hana::plus_impl< T, U, when< condition > >, boost::hana::power_impl< R, when< condition > >, boost::hana::prefix_impl< M, when< condition > >, boost::hana::prepend_impl< M, when< condition > >, boost::hana::product_impl< T, when< condition > >, boost::hana::remove_at_impl< S, when< condition > >, boost::hana::remove_if_impl< M, when< condition > >, boost::hana::remove_impl< M, when< condition > >, boost::hana::remove_range_impl< S, when< condition > >, boost::hana::repeat_impl< I, when< condition > >, boost::hana::replace_if_impl< Fun, when< condition > >, boost::hana::replace_impl< Fun, when< condition > >, boost::hana::replicate_impl< M, when< condition > >, boost::hana::reverse_impl< S, when< condition > >, boost::hana::scan_left_impl< S, when< condition > >, boost::hana::scan_right_impl< S, when< condition > >, boost::hana::second_impl< P, when< condition > >, boost::hana::slice_impl< S, when< condition > >, boost::hana::sort_impl< S, when< condition > >, boost::hana::span_impl< S, when< condition > >, boost::hana::suffix_impl< M, when< condition > >, boost::hana::sum_impl< T, when< condition > >, boost::hana::symmetric_difference_impl< S, when< condition > >, boost::hana::take_back_impl< S, when< condition > >, boost::hana::take_front_impl< S, when< condition > >, boost::hana::take_while_impl< S, when< condition > >, boost::hana::tap_impl< M, when< condition > >, boost::hana::then_impl< M, when< condition > >, boost::hana::transform_impl< Fun, when< condition > >, boost::hana::unfold_left_impl< S, when< condition > >, boost::hana::unfold_right_impl< S, when< condition > >, boost::hana::union_impl< S, when< condition > >, boost::hana::unique_impl< S, when< condition > >, boost::hana::unpack_impl< T, when< condition > >, boost::hana::value_impl< C, when< condition > >, boost::hana::while_impl< L, hana::when< condition > >, boost::hana::zero_impl< M, when< condition > >, boost::hana::zip_impl< S, when< condition > >, boost::hana::zip_shortest_impl< S, when< condition > >, and boost::hana::zip_shortest_with_impl< S, when< condition > >.