### Hana Tuple Creation Example Source: https://boostorg.github.io/hana/fwd_2difference_8hpp Example showing how to create and use Hana tuples. ```cpp #include auto t = boost::hana::tuple_tag{}; auto my_tuple = t(1, 'a', "hello"); ``` -------------------------------- ### Hana `partition` Example Source: https://boostorg.github.io/hana/fwd_2difference_8hpp Example of using `partition` to split a sequence into two based on a predicate. ```cpp #include auto is_even = [](auto x){ return x % 2 == 0; }; auto numbers = boost::hana::make_tuple(1, 2, 3, 4, 5, 6); auto partitioned = boost::hana::partition(numbers, is_even); // partitioned will be boost::hana::make_tuple(boost::hana::make_tuple(2, 4, 6), boost::hana::make_tuple(1, 3, 5)) ``` -------------------------------- ### Hana `take_while` Example Source: https://boostorg.github.io/hana/fwd_2difference_8hpp Example usage of `take_while` to select elements from the beginning of a sequence as long as a condition holds. ```cpp #include auto is_even = [](auto x){ return x % 2 == 0; }; auto sequence = boost::hana::make_tuple(2, 4, 6, 7, 8, 10); auto result = boost::hana::take_while(sequence, is_even); // result will be boost::hana::make_tuple(2, 4, 6) ``` -------------------------------- ### Hana `cycle` Example Source: https://boostorg.github.io/hana/fwd_2difference_8hpp Example demonstrating the `cycle` utility to create an infinite sequence by repeating a finite one. ```cpp #include #include auto short_list = boost::hana::make_tuple(1, 2); auto cycled_list = boost::hana::cycle(short_list); auto first_five = boost::hana::take_front(cycled_list, boost::hana::integral_constant{}); // first_five will be boost::hana::make_tuple(1, 2, 1, 2, 1) ``` -------------------------------- ### Hana `zip_shortest` Example Source: https://boostorg.github.io/hana/fwd_2difference_8hpp Example of using `zip_shortest` to combine elements from multiple sequences until the shortest one is exhausted. ```cpp #include auto xs = boost::hana::make_tuple(1, 2, 3); auto ys = boost::hana::make_tuple('a', 'b'); auto zipped = boost::hana::zip_shortest(xs, ys); // zipped will be boost::hana::make_tuple(boost::hana::make_tuple(1, 'a'), boost::hana::make_tuple(2, 'b')) ``` -------------------------------- ### Hana `for_each` Example Source: https://boostorg.github.io/hana/fwd_2difference_8hpp Example of using `for_each` to apply a function to each element of a sequence for side effects. ```cpp #include #include auto print_element = [](auto x){ std::cout << x << " "; }; auto numbers = boost::hana::make_tuple(1, 2, 3); boost::hana::for_each(numbers, print_element); // Output: 1 2 3 ``` -------------------------------- ### Hana `zip_with` Example Source: https://boostorg.github.io/hana/fwd_2difference_8hpp Example of using `zip_with` to combine elements from multiple sequences using a provided function. ```cpp #include #include auto xs = boost::hana::make_tuple(1, 2, 3); auto ys = boost::hana::make_tuple(10, 20, 30); auto summed = boost::hana::zip_with(boost::hana::plus, xs, ys); // summed will be boost::hana::make_tuple(11, 22, 33) ``` -------------------------------- ### Hana Struct Adaptation Example Source: https://boostorg.github.io/hana/fwd_2difference_8hpp An example demonstrating how to adapt a simple C++ struct to be used with Boost.Hana's generic algorithms. ```cpp struct Point { int x; int y; }; BOOST_HANA_ADAPT_STRUCT(Point, x, y); ``` -------------------------------- ### Hana `group` Example Source: https://boostorg.github.io/hana/fwd_2difference_8hpp Example of using `group` to group consecutive identical elements in a sequence. ```cpp #include auto sequence = boost::hana::make_tuple(1, 1, 2, 3, 3, 3, 4, 4); auto grouped = boost::hana::group(sequence); // grouped will be boost::hana::make_tuple(boost::hana::make_tuple(1, 1), boost::hana::make_tuple(2), boost::hana::make_tuple(3, 3 ``` -------------------------------- ### Hana `reverse` Example Source: https://boostorg.github.io/hana/fwd_2difference_8hpp Example of using `reverse` to create a new sequence with elements in the opposite order. ```cpp #include auto original_tuple = boost::hana::make_tuple(1, 2, 3); auto reversed_tuple = boost::hana::reverse(original_tuple); // reversed_tuple will be boost::hana::make_tuple(3, 2, 1) ``` -------------------------------- ### Hana `transform` Example Source: https://boostorg.github.io/hana/fwd_2difference_8hpp Example of using `transform` (similar to map) to apply a function to each element and create a new sequence. ```cpp #include auto square = [](auto x){ return x * x; }; auto numbers = boost::hana::make_tuple(1, 2, 3); auto squares = boost::hana::transform(numbers, square); // squares will be boost::hana::make_tuple(1, 4, 9) ``` -------------------------------- ### Hana `flatten` Example Source: https://boostorg.github.io/hana/fwd_2difference_8hpp Example of using `flatten` to combine nested sequences into a single-level sequence. ```cpp #include auto nested_tuple = boost::hana::make_tuple(boost::hana::make_tuple(1, 2), boost::hana::make_tuple(3, 4)); auto flat_tuple = boost::hana::flatten(nested_tuple); // flat_tuple will be boost::hana::make_tuple(1, 2, 3, 4) ``` -------------------------------- ### Hana `scan_right` Example Source: https://boostorg.github.io/hana/fwd_2difference_8hpp Example of using `scan_right` to perform a right-associative scan. ```cpp #include #include auto numbers = boost::hana::make_tuple(1, 2, 3, 4); auto scan_result = boost::hana::scan_right(numbers, boost::hana::int_c<0>, boost::hana::plus); // scan_result will be boost::hana::make_tuple(10, 9, 7, 4, 0) ``` -------------------------------- ### Hana `filter` Example Source: https://boostorg.github.io/hana/fwd_2difference_8hpp Example of using `filter` to select elements from a sequence that satisfy a given predicate. ```cpp #include auto is_even = [](auto x){ return x % 2 == 0; }; auto numbers = boost::hana::make_tuple(1, 2, 3, 4, 5); auto even_numbers = boost::hana::filter(numbers, is_even); // even_numbers will be boost::hana::make_tuple(2, 4) ``` -------------------------------- ### Hana `find_if` Example Source: https://boostorg.github.io/hana/fwd_2difference_8hpp Example usage of the `find_if` algorithm to locate the first element satisfying a condition. ```cpp #include auto is_even = [](auto x){ return x % 2 == 0; }; auto result = boost::hana::find_if(boost::hana::make_tuple(1, 3, 4, 5), is_even); // result will contain boost::hana::make_tuple(4) ``` -------------------------------- ### Boost.Hana Map Event System Example Source: https://boostorg.github.io/hana/structboost_1_1hana_1_1map An example showcasing the use of hana::map to build an event system where events are mapped to a list of callback functions. ```APIDOC ## Example ```cpp // Copyright Louis Dionne 2013-2017 // Distributed under the Boost Software License, Version 1.0. #include #include #include #include #include #include #include #include #include namespace hana = boost::hana; template struct event_system { using Callback = std::function; hana::map>...> map_; template void on(Event e, F handler) { auto is_known_event = hana::contains(map_, e); static_assert(is_known_event, "trying to add a handler to an unknown event"); map_[e].push_back(handler); } template void trigger(Event e) const { auto is_known_event = hana::contains(map_, e); static_assert(is_known_event, "trying to trigger an unknown event"); for (auto& handler : this->map_[e]) handler(); } }; template event_system make_event_system(Events ...events) { return {}; } int main() { auto events = make_event_system( BOOST_HANA_STRING("foo"), BOOST_HANA_STRING("bar"), BOOST_HANA_STRING("baz") ); std::vector triggered_events; events.on(BOOST_HANA_STRING("foo"), [&] { triggered_events.push_back("foo:1"); }); events.on(BOOST_HANA_STRING("foo"), [&] { triggered_events.push_back("foo:2"); }); events.on(BOOST_HANA_STRING("bar"), [&] { triggered_events.push_back("bar:1"); }); events.on(BOOST_HANA_STRING("baz"), [&] { triggered_events.push_back("baz:1"); }); events.trigger(BOOST_HANA_STRING("foo")); events.trigger(BOOST_HANA_STRING("bar")); events.trigger(BOOST_HANA_STRING("baz")); BOOST_HANA_RUNTIME_CHECK(triggered_events == std::vector{ "foo:1", "foo:2", "bar:1", "baz:1" }); } ``` ``` -------------------------------- ### Hana `drop_while` Example Source: https://boostorg.github.io/hana/fwd_2difference_8hpp Example usage of `drop_while` to remove elements from the beginning of a sequence as long as a condition holds. ```cpp #include auto is_less_than_5 = [](auto x){ return x < 5; }; auto sequence = boost::hana::make_tuple(1, 3, 5, 7, 2, 4); auto result = boost::hana::drop_while(sequence, is_less_than_5); // result will be boost::hana::make_tuple(5, 7, 2, 4) ``` -------------------------------- ### Hana Event System Example Source: https://boostorg.github.io/hana/structboost_1_1hana_1_1map An example of an event system using Boost.Hana maps. It defines an event system that allows registering callbacks for specific events and triggering those events. Requires boost/hana/assert.hpp, boost/hana/at_key.hpp, boost/hana/contains.hpp, boost/hana/map.hpp, boost/hana/pair.hpp, boost/hana/string.hpp. ```cpp // Copyright Louis Dionne 2013-2017 // Distributed under the Boost Software License, Version 1.0. #include #include #include #include #include #include #include #include #include namespace hana = boost::hana; template struct event_system { using Callback = std::function; hana::map>...> map_; template void on(Event e, F handler) { auto is_known_event = hana::contains(map_, e); static_assert(is_known_event, "trying to add a handler to an unknown event"); map_[e].push_back(handler); } template void trigger(Event e) const { auto is_known_event = hana::contains(map_, e); static_assert(is_known_event, "trying to trigger an unknown event"); for (auto& handler : this->map_[e]) handler(); } }; template event_system make_event_system(Events ...events) { return {}; } int main() { auto events = make_event_system( BOOST_HANA_STRING("foo"), BOOST_HANA_STRING("bar"), BOOST_HANA_STRING("baz") ); std::vector triggered_events; events.on(BOOST_HANA_STRING("foo"), [&] { triggered_events.push_back("foo:1"); }); events.on(BOOST_HANA_STRING("foo"), [&] { triggered_events.push_back("foo:2"); }); events.on(BOOST_HANA_STRING("bar"), [&] { triggered_events.push_back("bar:1"); }); events.on(BOOST_HANA_STRING("baz"), [&] { triggered_events.push_back("baz:1"); }); events.trigger(BOOST_HANA_STRING("foo")); events.trigger(BOOST_HANA_STRING("bar")); events.trigger(BOOST_HANA_STRING("baz")); BOOST_HANA_RUNTIME_CHECK(triggered_events == std::vector{ "foo:1", "foo:2", "bar:1", "baz:1" }); } ``` -------------------------------- ### Zip Function Example (Boost.Hana) Source: https://boostorg.github.io/hana/fwd_2fold_8hpp Demonstrates the `zip` function in Boost.Hana, which combines elements from multiple sequences into tuples. ```cpp #include #include auto t1 = boost::hana::make_tuple(1, 2, 3); auto t2 = boost::hana::make_tuple('a', 'b', 'c'); auto zipped = boost::hana::zip(t1, t2); ``` -------------------------------- ### C++: Basic Tag Dispatching Setup Source: https://boostorg.github.io/hana/index Demonstrates the fundamental structure for tag dispatching. It includes a customizable implementation struct (`print_impl`) and a public interface function (`print`) that dispatches calls based on the `tag_of` the argument. This setup allows for specialized behavior without modifying the original types. ```cpp template struct print_impl { template static void apply(std::ostream&, X const&) { // possibly some default implementation } }; template void print(std::ostream& os, X x) { using Tag = typename hana::tag_of::type; print_impl::apply(os, x); } ``` -------------------------------- ### Map Creation Example (Boost.Hana) Source: https://boostorg.github.io/hana/fwd_2fold_8hpp Illustrates how to create a map in Boost.Hana. Maps are associative containers that store key-value pairs. ```cpp #include auto m = boost::hana::make_map(boost::hana::make_pair("key1", 1), boost::hana::make_pair("key2", 2)); ``` -------------------------------- ### Integrating Hana with CMake Source: https://boostorg.github.io/hana/index This example shows how to find and link the Hana library in a CMake project. After Hana is installed (manually or via Boost), CMake's find_package can locate it, and the 'hana' target can be linked to your executable. CMAKE_PREFIX_PATH may be needed for non-standard installations. ```cmake cmake_minimum_required(VERSION 3.0) project(external CXX) find_package(Hana REQUIRED) add_executable(external main.cpp) target_link_libraries(external hana) ``` -------------------------------- ### Boost.Hana: Hana Header Source: https://boostorg.github.io/hana/fwd_2slice_8hpp The main header file for Boost.Hana, providing access to most of the library's functionalities. It's often included to get started with Hana. ```cpp #include ``` -------------------------------- ### Boost.Hana size function example Source: https://boostorg.github.io/hana/group__group-_foldable Demonstrates the usage of boost::hana::size to get the size of different structures, including tuples and optionals. It checks against compile-time constants. ```cpp #include #include #include #include #include #include namespace hana = boost::hana; int main() { BOOST_HANA_CONSTANT_CHECK(hana::size(hana::make_tuple()) == hana::size_c<0>); BOOST_HANA_CONSTANT_CHECK(hana::size(hana::make_tuple(1, '2', 3.0)) == hana::size_c<3>); BOOST_HANA_CONSTANT_CHECK(hana::size(hana::nothing) == hana::size_c<0>); BOOST_HANA_CONSTANT_CHECK(hana::size(hana::just('x')) == hana::size_c<1>); } ``` -------------------------------- ### Boost.Hana fold_left Example Source: https://boostorg.github.io/hana/group__group-_sequence Demonstrates the usage of boost::hana::fold_left with a tuple. It applies a binary function to accumulate a result, starting with an initial value. Dependencies include boost/hana/assert.hpp, boost/hana/fold_left.hpp, and boost/hana/tuple.hpp. ```cpp #include #include #include #include namespace hana = boost::hana; auto to_string = [](auto x) { std::ostringstream ss; ss << x; return ss.str(); }; auto show = [](auto x, auto y) { return "(" + to_string(x) + " + " + to_string(y) + ")"; }; int main() { BOOST_HANA_RUNTIME_CHECK( hana::fold_left(hana::make_tuple(2, "3", '4'), "1", show) == "(((1 + 2) + 3) + 4)" ); } ``` -------------------------------- ### Hana Tuple Initialization Source: https://boostorg.github.io/hana/structboost_1_1hana_1_1detail_1_1array-members Provides examples of creating and using Hana tuples, fixed-size sequences of heterogeneous elements that are central to Hana's compile-time programming capabilities. ```cpp hana::tuple_tag; hana::tuple{}; ``` -------------------------------- ### Manual Installation with CMake Source: https://boostorg.github.io/hana/index This snippet demonstrates how to manually install the Hana library using CMake. It involves creating a build directory, configuring the project with CMake, and then building and installing it. The installation path can be customized using CMAKE_INSTALL_PREFIX. ```bash mkdir build cd build cmake .. cmake --build . --target install ``` -------------------------------- ### Take first N elements from Hana tuple with take_front_c Source: https://boostorg.github.io/hana/group__group-_sequence Demonstrates the use of boost::hana::take_front_c to get the first N elements from a Hana tuple, where N is specified as a compile-time constant. This function provides a convenient way to achieve the same result as `take_front` when the count is fixed at compile time. The example verifies taking the first 2 elements. ```cpp #include #include #include namespace hana = boost::hana; static_assert(hana::take_front_c<2>(hana::make_tuple(1, '2', 3.3)) == hana::make_tuple(1, '2'), ""); int main() { } ``` -------------------------------- ### Metaprogramming Utilities: Apply and Curry in Boost.Hana Source: https://boostorg.github.io/hana/fwd_2set_8hpp Demonstrates the `apply` and `curry` utilities from Boost.Hana, enabling flexible function application and partial application for metaprogramming. ```cpp #include #include #include #include auto multiply = [](auto a, auto b){ return a * b; }; // Applying a function to arguments from a tuple auto result_apply = boost::hana::apply(multiply, boost::hana::make_tuple(4, 5)); // Currying a function auto curried_multiply = boost::hana::curry(multiply); auto partial_multiply = curried_multiply(4); auto final_result = partial_multiply(5); // Unpacking arguments for a function // auto result_unpack = boost::hana::unpack(boost::hana::make_tuple(4, 5), multiply); ``` -------------------------------- ### Iterate over types with boost::hana::for_each and boost::hana::tuple Source: https://boostorg.github.io/hana/structboost_1_1hana_1_1basic__type This example demonstrates how to use `boost::hana::for_each` to iterate over a `boost::hana::tuple_t` of types. It utilizes `boost::hana::basic_type` to obtain type information and `boost::core::demangle` to get human-readable type names. This pattern is useful for compile-time operations involving multiple types. ```C++ #include #include #include #include #include #include #include namespace hana = boost::hana; template std::string const& name_of(hana::basic_type) { static std::string name = boost::core::demangle(typeid(T).name()); return name; } int main() { hana::for_each(hana::tuple_t, [](auto type) { std::cout << name_of(type) << std::endl; }); } ``` -------------------------------- ### Boost.Hana Adapters Overview Source: https://boostorg.github.io/hana/group__group-ext-boost This section provides an overview of the adapters available in Boost.Hana for different container types. ```APIDOC ## External Adapters Boost.Hana provides adapters for several external libraries and standard library components to enable seamless integration. ### Boost.Fusion Adapters Adapters for containers and algorithms from the Boost.Fusion library. ### Boost.MPL Adapters Adapters for types and metafunctions from the Boost.MPL library. ### Other Boost Adapters Adapters for various other Boost libraries not covered by Fusion or MPL. ### Standard Library Adapters Adapters for standard C++ library containers and types, such as `std::tuple`, `std::array`, `std::pair`, etc. ## Classes ### `struct boost::tuple< T >` Adapter for `boost::tuple`s. This structure provides Hana-compliant access and manipulation for `boost::tuple` objects. ``` -------------------------------- ### Hana `scan_left` Example Source: https://boostorg.github.io/hana/fwd_2difference_8hpp Example of using `scan_left` to perform a left-associative scan (prefix sum). ```cpp #include #include auto numbers = boost::hana::make_tuple(1, 2, 3, 4); auto scan_result = boost::hana::scan_left(numbers, boost::hana::int_c<0>, boost::hana::plus); // scan_result will be boost::hana::make_tuple(0, 1, 3, 6, 10) ``` -------------------------------- ### Boost.Hana Adapters and Utilities Source: https://boostorg.github.io/hana/group__group-_monoid Information on external adapters, experimental features, and miscellaneous utilities provided by Boost.Hana. ```APIDOC ## Adapters and Utilities Explore external adapters, experimental features, and useful utilities in Boost.Hana. ### External Adapters - **External adapters**: Integrations with other libraries and C++ features. ### Experimental Features - **Experimental features**: Cutting-edge features under development. ### Miscellaneous Utilities - **Alphabetical index**: An index of all available components. - **Headers**: List of header files for Boost.Hana. - **Todo List**: Items for future development. - **Bug List**: Known issues and their status. - **Deprecated List**: Features that are no longer recommended for use. - **deque**: Double-ended queue. - **list**: Linked list. - **tuple**: Tuple data structure. - **vector**: Dynamic array. - **which**: A utility for type introspection. - **adl**: Argument-dependent lookup utilities. - **any_of**: Checks if any element satisfies a predicate. - **array**: Fixed-size array. - **CanonicalConstant**: A canonical representation of a constant. - **create**: Function to create instances. - **decay**: Decay type utility. - **first_unsatisfied_index**: Finds the index of the first unsatisfied element. - **has_duplicates**: Checks for duplicate elements. - **nested_by**: Groups elements by a criterion. - **nested_than**: Groups elements lexicographically. - **nested_to**: Groups elements into a specific structure. - **std_common_type**: Obtains the common type of a set of types. - **type_at**: Retrieves a type at a specific index. - **wrong**: Represents an invalid or missing value. - **has_common_embedding**: Checks for common embedding between types. - **has_nontrivial_common_embedding**: Checks for nontrivial common embedding. - **types**: A collection of types. - **type_name**: Retrieves the name of a type. - **print**: Function to print values. - **operator""_c**: User-defined literal for character constants. - **operator""_s**: User-defined literal for string constants. - **has_common**: Checks for commonality between types. - **is_default**: Checks if a type has a default constructor. - **is_convertible**: Checks if a type is convertible to another. - **is_embedded**: Checks if a type is embedded within another. - **integral_constant_tag**: Tag for integral constants. - **integral_constant**: Represents an integral constant. - **basic_tuple**: A basic tuple implementation. - **basic_tuple_tag**: Tag for basic tuples. - **IntegralConstant**: Alias for integral_constant. - **common**: Common type utility. - **default_**: Default value utility. - **tag_of**: Retrieves the tag of a type. - **embedding**: Embedding utility. - **when**: Conditional evaluation utility. - **lazy**: Lazy evaluation wrapper. - **lazy_tag**: Tag for lazy evaluation. - **map_tag**: Tag for map data structure. - **map**: Key-value mapping. - **optional**: Optional value wrapper. - **optional_tag**: Tag for optional values. - **pair**: Pair data structure. - **pair_tag**: Tag for pairs. - **range**: Range representation. - **range_tag**: Tag for ranges. - **set**: Set data structure. - **set_tag**: Tag for sets. - **string**: String data structure. - **string_tag**: Tag for strings. - **tuple_tag**: Tag for tuples. - **basic_type**: Basic type utility. - **type_tag**: Tag for types. - **common_t**: Common type alias. - **tag_of_t**: Type alias for tag_of. - **when_valid**: Conditional evaluation for valid types. - **BOOST_HANA_ADAPT_ADT**: Macro for adapting algebraic data types. - **BOOST_HANA_ADAPT_STRUCT**: Macro for adapting structs. - **A**: Placeholder for type argument. - **BOOST_HANA_DEFINE_STRUCT**: Macro for defining structs. - **mathtt**: Math text formatting. - **mathrm**: Roman math font. ``` -------------------------------- ### Boost.Hana Basic Tuple Example Source: https://boostorg.github.io/hana/adapt__adt_8hpp Illustrates the creation and usage of Boost.Hana's basic_tuple, a compile-time heterogeneous container. It shows how to access elements by index. ```C++ #include int main() { auto t = boost::hana::make_tuple(1, "hello", 3.14); static_assert(boost::hana::at_c<0>(t) == 1, "First element should be 1"); static_assert(boost::hana::at_c<1>(t) == "hello", "Second element should be \"hello\""); return 0; } ``` -------------------------------- ### Boost.Hana Details Source: https://boostorg.github.io/hana/group__group-_metafunction In-depth explanations of specific design choices, implementation details, and advanced topics in Boost.Hana. ```APIDOC ## Details ### Description In-depth explanations of Boost.Hana's internal workings, design patterns, and advanced usage. ### Topics - Explanation of the metaprogramming techniques employed. - Discussion of performance considerations. - Advanced usage patterns and examples. ``` -------------------------------- ### Hana `fold_right` Example Source: https://boostorg.github.io/hana/fwd_2difference_8hpp Example of using `fold_right` (right reduction) to aggregate elements of a sequence. ```cpp #include #include auto numbers = boost::hana::make_tuple(1, 2, 3, 4, 5); auto sum = boost::hana::fold_right(numbers, boost::hana::int_c<0>, boost::hana::plus); // sum will be 15 ``` -------------------------------- ### Hana `fold_left` Example Source: https://boostorg.github.io/hana/fwd_2difference_8hpp Example of using `fold_left` (left reduction) to aggregate elements of a sequence. ```cpp #include #include auto numbers = boost::hana::make_tuple(1, 2, 3, 4, 5); auto sum = boost::hana::fold_left(numbers, boost::hana::int_c<0>, boost::hana::plus); // sum will be 15 ``` -------------------------------- ### Adapting std::tuple with Boost.Hana Source: https://boostorg.github.io/hana/index Demonstrates how to adapt `std::tuple` for use with Boost.Hana by including the necessary headers and using the `hana::front` algorithm. This example requires including the `boost/hana/ext/std/tuple.hpp` for the adapter, `boost/hana/front.hpp` for the algorithm, and the standard `` header. ```C++ #include #include #include // still required to create a tuple namespace hana = boost::hana; int main() { constexpr std::tuple xs{1, '2', 3.0f}; static_assert(hana::front(xs) == 1, ""); } ``` -------------------------------- ### Hana `count_if` Example Source: https://boostorg.github.io/hana/fwd_2difference_8hpp Example usage of the `count_if` algorithm to count elements satisfying a condition. ```cpp #include auto is_odd = [](auto x){ return x % 2 != 0; }; auto count = boost::hana::count_if(boost::hana::make_tuple(1, 2, 3, 4, 5), is_odd); // count will be 3 ``` -------------------------------- ### Boost.MPL Adapters Source: https://boostorg.github.io/hana/structboost_1_1mpl_1_1list Documentation for adapters that integrate Boost.Hana with Boost.MPL, specifically for lists. ```APIDOC ## struct boost::mpl::list< T > ### Description Adapter for Boost.MPL lists. ### Method N/A ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Boost.Hana trait Alias Example Source: https://boostorg.github.io/hana/group__group-_metafunction Illustrates the usage of the `trait` alias in Boost.Hana, which is a convenience wrapper around `integral(metafunction)`. This example demonstrates adapting `std::is_integral` to check if a type is integral, using Hana's assertion macros for verification. It requires the same headers as the `integral` example. ```cpp #include #include #include #include #include namespace hana = boost::hana; BOOST_HANA_CONSTANT_CHECK(hana::trait(hana::type_c)); BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::trait(hana::type_c))); int main() { } ``` -------------------------------- ### Boost.Hana Core Features Source: https://boostorg.github.io/hana/group__group-_comparable Documentation for the core features of Boost.Hana, including metaprogramming utilities and compile-time computations. ```APIDOC ## Core Features ### Description This section covers the fundamental features and utilities of Boost.Hana that enable powerful compile-time metaprogramming. ### Features - **BOOST_HANA_ADAPT_ADT**: Macro for adapting algebraic data types. - **BOOST_HANA_ADAPT_STRUCT**: Macro for adapting structs. - **BOOST_HANA_DEFINE_STRUCT**: Macro for defining structs. - **IntegralConstant**: Represents a compile-time integral constant. - **CanonicalConstant**: Represents a canonical compile-time constant. - **create**: Utility for creating objects. - **decay**: Utility for decaying types. - **first_unsatisfied_index**: Finds the index of the first element that does not satisfy a predicate. - **has_duplicates**: Checks if a sequence has duplicate elements. - **nested_by**: Groups elements based on a function. - **nested_than**: Groups elements based on a comparison function. - **nested_to**: Groups elements based on a transformation and comparison. - **std_common_type**: Computes the common type of a sequence of types. - **type_at**: Retrieves the type at a specific index. - **wrong**: Represents an incorrect type or value. - **has_common**: Checks for common elements between sequences. - **is_default**: Checks if a type has a default value. - **is_convertible**: Checks if a type is convertible to another. - **is_embedded**: Checks if a type is embedded. - **integral_constant_tag**: Tag for integral constants. - **basic_tuple_tag**: Tag for basic tuples. - **lazy_tag**: Tag for lazy evaluation. - **map_tag**: Tag for maps. - **optional_tag**: Tag for optionals. - **pair_tag**: Tag for pairs. - **range_tag**: Tag for ranges. - **set_tag**: Tag for sets. - **string_tag**: Tag for strings. - **tuple_tag**: Tag for tuples. - **basic_type**: Represents a basic type. - **type_tag**: Tag for types. - **common_t**: Computes the common type. - **tag_of_t**: Retrieves the tag of a type. - **when_valid**: Conditional evaluation. - **integral_c**: Factory for integral constants. - **list**: List data structure. - **vector**: Dynamic array. - **tuple**: Heterogeneous collection. - **array**: Fixed-size array. - **integer_sequence**: Sequence of integers. - **integral_constant**: Compile-time integral constant. - **pair**: Holds two values. - **ratio**: Represents a ratio of two integers. - **deque**: Double-ended queue. - **which**: Utility for type introspection. - **adl**: Access ADL (Argument-Dependent Lookup). - **any_of**: Checks if any element satisfies a predicate. - **CanonicalConstant**: Represents a canonical compile-time constant. - **create**: Utility for creating objects. - **decay**: Utility for decaying types. - **first_unsatisfied_index**: Finds the index of the first element that does not satisfy a predicate. - **has_duplicates**: Checks if a sequence has duplicate elements. - **nested_by**: Groups elements based on a function. - **nested_than**: Groups elements based on a comparison function. - **nested_to**: Groups elements based on a transformation and comparison. - **std_common_type**: Computes the common type of a sequence of types. - **type_at**: Retrieves the type at a specific index. - **wrong**: Represents an incorrect type or value. - **types**: Represents a collection of types. - **has_common**: Checks for common elements between sequences. - **is_default**: Checks if a type has a default value. - **is_convertible**: Checks if a type is convertible to another. - **is_embedded**: Checks if a type is embedded. - **integral_constant_tag**: Tag for integral constants. - **basic_tuple_tag**: Tag for basic tuples. - **IntegralConstant**: Represents a compile-time integral constant. - **common**: Utility for common types. - **default_**: Represents a default value. - **tag_of**: Retrieves the tag of a type. - **embedding**: Information about type embedding. - **when**: Conditional evaluation. - **lazy_tag**: Tag for lazy evaluation. - **map_tag**: Tag for maps. - **optional_tag**: Tag for optionals. - **pair_tag**: Tag for pairs. - **range_tag**: Tag for ranges. - **set_tag**: Tag for sets. - **string_tag**: Tag for strings. - **tuple_tag**: Tag for tuples. - **basic_type**: Represents a basic type. - **type_tag**: Tag for types. - **integral_c**: Factory for integral constants. - **list**: List data structure. - **vector**: Dynamic array. - **tuple**: Heterogeneous collection. - **array**: Fixed-size array. - **integer_sequence**: Sequence of integers. - **integral_constant**: Compile-time integral constant. - **pair**: Holds two values. - **ratio**: Represents a ratio of two integers. - **tuple**: Heterogeneous collection. ``` -------------------------------- ### Metaprogramming Utilities: Capture and Partial Application in Boost.Hana Source: https://boostorg.github.io/hana/fwd_2set_8hpp Demonstrates `capture` for creating functions with captured environments and `partial` for partial application of functions using Boost.Hana. ```cpp #include #include #include auto env_value = 10; // Capturing a value into a function auto captured_add = boost::hana::capture(env_value, [](auto captured, auto x){ return captured + x; }); // auto result_capture = captured_add(5); auto add = [](auto a, auto b){ return a + b; }; // Partial application of the first argument auto partial_add_5 = boost::hana::partial(add, boost::hana::int_c<5>); // auto result_partial = partial_add_5(3); ``` -------------------------------- ### Boost.Hana - Basic Tuple Operations Source: https://boostorg.github.io/hana/structboost_1_1hana_1_1detail_1_1nested__to Demonstrates fundamental operations on Boost.Hana's basic_tuple, a versatile data structure. Includes examples of common, default, tag_of, embedding, and when functions. ```cpp #include #include #include #include #include namespace hana = boost::hana; int main() { auto bt = hana::basic_tuple_tag; auto common_bt = hana::common(bt); auto default_bt = hana::default_(bt); auto tag_of_bt = hana::tag_of(bt); auto when_bt = hana::when(bt); // Example usage would go here, demonstrating operations on basic_tuple return 0; } ``` -------------------------------- ### Boost.Hana Core and Configuration Source: https://boostorg.github.io/hana/group__group-_monoid Documentation for Boost.Hana's core components, configuration options, and assertion utilities. ```APIDOC ## Core and Configuration This section covers the core functionalities and configuration aspects of Boost.Hana. ### Core Components - **Core**: Fundamental building blocks of Boost.Hana. - **Assertions**: Utilities for asserting conditions during metaprogramming. - **Details**: Internal implementation details and helper utilities. ### Configuration Options - **Configuration options**: How to configure Boost.Hana for specific needs. ``` -------------------------------- ### Basic Tuple Example (Boost.Hana) Source: https://boostorg.github.io/hana/fwd_2fold_8hpp Demonstrates the creation and usage of a basic tuple in Boost.Hana. Tuples are heterogeneous data structures that can hold elements of different types. ```cpp #include auto t = boost::hana::make_tuple(1, 'a', "hello"); ``` -------------------------------- ### Boost.Hana List Adapter Source: https://boostorg.github.io/hana/structboost_1_1fusion_1_1list Documentation for the Boost.Hana adapter for Boost.Fusion lists, detailing its structure and usage. ```APIDOC ## Boost.Hana List Adapter ### Description This section describes the `boost::fusion::list` adapter provided by Boost.Hana. It allows Boost.Fusion lists to be used seamlessly within the Boost.Hana framework, leveraging its metaprogramming capabilities. ### Method N/A (This describes a type adapter, not an API endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ```