//// Copyright 2017 Peter Dimov Distributed under the Boost Software License, Version 1.0. See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt //// [#list] # List Operations, :toc: :toc-title: :idprefix: ## mp_list template struct mp_list {}; `mp_list` is the standard list type of Mp11, although the library is not restricted to it and can operate on arbitrary class templates such as `std::tuple` or `std::variant`. Even `std::pair` can be used if the transformation does not alter the number of the elements in the list. ## mp_list_c template using mp_list_c = mp_list...>; `mp_list_c` produces an `mp_list` of the `std::integral_constant` types corresponding to its integer template arguments. .Using mp_list_c ``` using L1 = mp_list_c; // mp_list, mp_int<3>> ``` ## mp_is_list template using mp_is_list = /*...*/; `mp_is_list` is `mp_true` if `L` is a list (an instantiation of a class template whose template parameters are types), `mp_false` otherwise. ## mp_size template using mp_size = /*...*/; `mp_size` returns the number of elements in the list `L`, as a `mp_size_t`. In other words, `mp_size>` is an alias for `mp_size_t`. .Using mp_size with mp_list ``` using L1 = mp_list<>; using R1 = mp_size; // mp_size_t\<0> ``` .Using mp_size with std::pair ``` using L2 = std::pair; using R2 = mp_size; // mp_size_t\<2> ``` .Using mp_size with std::tuple ``` using L3 = std::tuple; using R3 = mp_size; // mp_size_t\<1> ``` ## mp_empty template using mp_empty = mp_bool::value == 0>; `mp_empty` is an alias for `mp_true` if the list `L` is empty, for `mp_false` otherwise. .Using mp_empty with std::tuple ``` using L1 = std::tuple; using R1 = mp_empty; // mp_false using L2 = std::tuple<>; using R2 = mp_empty; // mp_true ``` ## mp_assign template using mp_assign = /*...*/; `mp_assign, L2>` is an alias for `L1`. That is, it replaces the elements of `L1` with those of `L2`. .Using mp_assign with mp_list and std::tuple ``` using L1 = std::tuple; using L2 = mp_list; using R1 = mp_assign; // std::tuple ``` .Using mp_assign with mp_list and std::pair ``` using L1 = std::pair; using L2 = mp_list; using R1 = mp_assign; // std::pair ``` ## mp_clear template using mp_clear = mp_assign>; `mp_clear>` is an alias for `L<>`, that is, it removes the elements of `L`. .Using mp_clear with std::tuple ``` using L1 = std::tuple; using R1 = mp_clear; // std::tuple<> ``` ## mp_front template using mp_front = /*...*/; `mp_front` is the first element of the list `L`. That is, `mp_front>` is an alias for `T1`. .Using mp_front with std::pair ``` using L1 = std::pair; using R1 = mp_front; // int ``` .Using mp_front with std::tuple ``` using L2 = std::tuple; using R2 = mp_front; // float ``` .Using mp_front with mp_list ``` using L3 = mp_list; using R3 = mp_front; // char[1] ``` ## mp_pop_front template using mp_pop_front = /*...*/; `mp_pop_front` removes the first element of the list `L`. That is, `mp_pop_front>` is an alias for `L`. .Using mp_pop_front with std::tuple ``` using L1 = std::tuple; using R1 = mp_pop_front; // std::tuple ``` .Using mp_pop_front with mp_list ``` using L2 = mp_list; using R2 = mp_pop_front; // mp_list<> ``` ## mp_first template using mp_first = mp_front; `mp_first` is another name for `mp_front`. ## mp_rest template using mp_rest = mp_pop_front; `mp_rest` is another name for `mp_pop_front`. ## mp_second template using mp_second = /*...*/; `mp_second` is the second element of the list `L`. That is, `mp_second>` is an alias for `T2`. .Using mp_second with std::pair ``` using L1 = std::pair; using R1 = mp_second; // float ``` .Using mp_second with std::tuple ``` using L2 = std::tuple; using R2 = mp_second; // double ``` .Using mp_second with mp_list ``` using L3 = mp_list; using R3 = mp_second; // char[2] ``` ## mp_third template using mp_third = /*...*/; `mp_third` is the third element of the list `L`. That is, `mp_third>` is an alias for `T3`. .Using mp_third with std::tuple ``` using L1 = std::tuple; using R1 = mp_third; // long double ``` .Using mp_third with mp_list ``` using L2 = mp_list; using R2 = mp_third; // char[3] ``` ## mp_push_front template using mp_push_front = /*...*/; `mp_push_front` inserts the elements `T...` at the front of the list `L`. That is, `mp_push_front, T...>` is an alias for `L`. .Using mp_push_front with std::tuple ``` using L1 = std::tuple; using R1 = mp_push_front; // std::tuple ``` .Using mp_push_front with mp_list ``` using L2 = mp_list; using R2 = mp_push_front; // mp_list ``` ## mp_push_back template using mp_push_back = /*...*/; `mp_push_back` inserts the elements `T...` at the back of the list `L`. That is, `mp_push_back, T...>` is an alias for `L`. .Using mp_push_back with std::tuple ``` using L1 = std::tuple; using R1 = mp_push_back; // std::tuple ``` .Using mp_push_back with mp_list ``` using L2 = mp_list; using R2 = mp_push_back; // mp_list ``` ## mp_rename template class Y> using mp_rename = /*...*/; `mp_rename` changes the type of the list `L` to `Y`. That is, `mp_rename, Y>` is an alias for `Y`. .Using mp_rename to rename std::pair to std::tuple ``` using L1 = std::pair; using R1 = mp_rename; // std::tuple ``` .Using mp_rename to rename std::tuple to mp_list ``` using L2 = std::tuple; using R2 = mp_rename; // mp_list ``` ## mp_apply template class F, class L> using mp_apply = mp_rename; `mp_apply` applies the metafunction `F` to the contents of the list `L`, that is, `mp_apply>` is an alias for `F`. (`mp_apply` is the same as `mp_rename` with the arguments reversed.) .Using mp_apply with std::pair ``` using L1 = std::pair; using R1 = mp_apply; // std::is_same ``` ## mp_apply_q template using mp_apply_q = mp_apply; Same as `mp_apply`, but takes a quoted metafunction. .Using mp_apply_q with mp_bind_front ``` using L1 = std::tuple; using L2 = mp_list; using R1 = mp_apply_q, L2>; // R1 is std::tuple ``` ## mp_append template using mp_append = /*...*/; `mp_append` concatenates the lists in `L...` into a single list that has the same type as the first list. `mp_append<>` is an alias for `mp_list<>`. `mp_append, L2, ..., Ln>` is an alias for `L1`. .Using mp_append with lists of various types ``` using L1 = std::tuple; using L2 = mp_list; using L3 = std::pair; using L4 = mp_list<>; using R1 = mp_append; // std::tuple ``` ## mp_replace_front template using mp_replace_front = /*...*/; `mp_replace_front` replaces the first element of the list `L` with `T`. That is, `mp_replace_front, T>` is an alias for `L`. .Using mp_replace_front with std::pair ``` using L1 = std::pair; using R1 = mp_replace_front; // std::pair ``` .Using mp_replace_front with std::tuple ``` using L2 = std::tuple; using R2 = mp_replace_front; // std::tuple ``` .Using mp_replace_front with mp_list ``` using L3 = mp_list; using R3 = mp_replace_front; // mp_list; ``` ## mp_replace_first template using mp_replace_first = mp_replace_front; `mp_replace_first` is another name for `mp_replace_front`. ## mp_replace_second template using mp_replace_second = /*...*/; `mp_replace_second` replaces the second element of the list `L` with `T`. That is, `mp_replace_second, T>` is an alias for `L`. .Using mp_replace_second with std::pair ``` using L1 = std::pair; using R1 = mp_replace_second; // std::pair ``` .Using mp_replace_second with std::tuple ``` using L2 = std::tuple; using R2 = mp_replace_second; // std::tuple ``` .Using mp_replace_front with mp_list ``` using L3 = mp_list; using R3 = mp_replace_second; // mp_list; ``` ## mp_replace_third template using mp_replace_third = /*...*/; `mp_replace_third` replaces the third element of the list `L` with `T`. That is, `mp_replace_third, T>` is an alias for `L`. .Using mp_replace_third with std::tuple ``` using L1 = std::tuple; using R1 = mp_replace_third; // std::tuple ``` .Using mp_replace_third with mp_list ``` using L2 = mp_list; using R2 = mp_replace_third; // mp_list; ``` ## mp_transform_front template class F> using mp_transform_front = /*...*/; `mp_transform_front` replaces the first element `T1` of the list `L` with `F`. ## mp_transform_front_q template using mp_transform_front_q = mp_transform_front; As `mp_transform_front`, but takes a quoted metafunction. ## mp_transform_first template class F> using mp_transform_first = mp_transform_front; `mp_transform_first` is another name for `mp_transform_front`. ## mp_transform_first_q template using mp_transform_first_q = mp_transform_first; As `mp_transform_first`, but takes a quoted metafunction. ## mp_transform_second template class F> using mp_transform_second = /*...*/; `mp_transform_second` replaces the second element `T2` of the list `L` with `F`. ## mp_transform_second_q template using mp_transform_second_q = mp_transform_second; As `mp_transform_second`, but takes a quoted metafunction. ## mp_transform_third template class F> using mp_transform_third = /*...*/; `mp_transform_third` replaces the third element `T3` of the list `L` with `F`. ## mp_transform_third_q template using mp_transform_third_q = mp_transform_third; As `mp_transform_third`, but takes a quoted metafunction.