//// 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_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 L1 = mp_list<>; using R1 = mp_size; // mp_size_t\<0> using L2 = std::pair; using R2 = mp_size; // mp_size_t\<2> 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. ## 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 L1 = std::pair; using R1 = mp_front; // int using L2 = std::tuple; using R2 = mp_front; // float 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 L1 = std::tuple; using R1 = mp_pop_front; // std::tuple 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 L1 = std::pair; using R1 = mp_second; // float using L2 = std::tuple; using R2 = mp_second; // double 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 L1 = std::tuple; using R1 = mp_third; // long double 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 L1 = std::tuple; using R1 = mp_push_front; // std::tuple 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 L1 = std::tuple; using R1 = mp_push_back; // std::tuple 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 L1 = std::pair; using R1 = mp_rename; // std::tuple 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 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 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 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 L1 = std::pair; using R1 = mp_replace_front; // std::pair using L2 = std::tuple; using R2 = mp_replace_front; // std::tuple 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 L1 = std::pair; using R1 = mp_replace_second; // std::pair using L2 = std::tuple; using R2 = mp_replace_second; // std::tuple 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 L1 = std::tuple; using R1 = mp_replace_third; // std::tuple using L2 = mp_list; using R2 = mp_replace_third; // mp_list;