@@ -19,13 +19,12 @@ std::ostream &operator<<(std::ostream &os, const std::type_info &ti) {
19
19
20
20
#define elided
21
21
22
- #include < yorel/yomm2/core.hpp>
23
22
#include < yorel/yomm2/compiler.hpp>
23
+ #include < yorel/yomm2/core.hpp>
24
24
#include < yorel/yomm2/symbols.hpp>
25
25
#include < yorel/yomm2/templates.hpp>
26
26
27
27
using namespace yorel ::yomm2;
28
- using boost::mp11::mp_list;
29
28
30
29
// md<
31
30
@@ -229,7 +228,6 @@ vector reals(new concrete_vector<double>{4., 5., 6.});
229
228
230
229
// code<
231
230
#include < yorel/yomm2/core.hpp>
232
- #include < yorel/yomm2/compiler.hpp>
233
231
#include < yorel/yomm2/symbols.hpp>
234
232
235
233
using namespace yorel ::yomm2;
@@ -293,9 +291,9 @@ inline bool operator==(const vector& a, const vector& b) {
293
291
// ```
294
292
295
293
// This "closed" approach is lazy, and defies the purpose of *open* methods. It
296
- // is not for the author of the library to decide which mp_list to support. The
294
+ // is not for the author of the library to decide which types to support. The
297
295
// user may have no interest in integer vectors, but may need `complex` vectors.
298
- // Or vectors of `decimal` floating-point numbers. Or, mp_list from another
296
+ // Or vectors of `decimal` floating-point numbers. Or, types from another
299
297
// library, or perhaps created by the user himself. An advanced user may also
300
298
// want to add new operations or vector subtypes (like large sparse vectors).
301
299
// All this must be possible, and not unduly complex. Extensibility is what open
@@ -311,14 +309,14 @@ inline bool operator==(const vector& a, const vector& b) {
311
309
// 1. Put the definitions in one or several templates, where the method being
312
310
// defined is the first template argument.
313
311
// 2. Create a meta-function that generates interesting combinations of methods
314
- // and mp_list .
312
+ // and types .
315
313
// 3. Instantiate the container(s) for these combinations. The resulting classes
316
314
// must satisfy the requirements of a definition container, *or* be derived
317
315
// from class `not_defined`. Add the definition containers to the method,
318
316
// extracted from the first template argument.
319
317
320
318
// The meta-programming library comprises:
321
- // - containers for mp_list and templates
319
+ // - containers for types and templates
322
320
// - meta-functions that generate Cartesian products of these containers.
323
321
// - a mechanism for instantiating the resulting definitions.
324
322
@@ -328,7 +326,7 @@ inline bool operator==(const vector& a, const vector& b) {
328
326
// 1. Make it very easy for a new user to use the library with all the defaults.
329
327
// 2. Make it easy for a "normal" user to specify which parts of the library to
330
328
// use.
331
- // 3. Make it possible for an advanced user to extend the library with new mp_list
329
+ // 3. Make it possible for an advanced user to extend the library with new types
332
330
// and new operations.
333
331
334
332
// Let's apply these ideas to the `vector` methods. First we declare a container
@@ -344,7 +342,7 @@ struct definition;
344
342
// md<
345
343
346
344
// Let's create partial specializations that defines addition, subtraction and
347
- // comparison for vectors or two underlying mp_list :
345
+ // comparison for vectors or two underlying types :
348
346
349
347
// >
350
348
@@ -403,15 +401,15 @@ struct definition<comparison, T, U> {
403
401
// ...then add the resulting definitions to their respective method.
404
402
405
403
// For the Cartesian product, we can use two constructs provided by YOMM2: the
406
- // `mp_list ` container, and the `product` meta-function.
404
+ // `types ` container, and the `product` meta-function.
407
405
408
- // `mp_list <typename...>` is a simple list of mp_list . It is similar to Boost.Mp11's
409
- // `mp_list`. Unlike `mp_list`, `mp_list ` does not have a body. This helps detect
406
+ // `types <typename...>` is a simple list of types . It is similar to Boost.Mp11's
407
+ // `mp_list`. Unlike `mp_list`, `types ` does not have a body. This helps detect
410
408
// meta-programming bugs.
411
409
412
- // `product<typename... TypeLists>` takes any number of `mp_list ` lists, and
413
- // returns a `mp_list ` list containing all the combinations of one element taken
414
- // from each input list, each combination being itself wrapped in a `mp_list `. For
410
+ // `product<typename... TypeLists>` takes any number of `types ` lists, and
411
+ // returns a `types ` list containing all the combinations of one element taken
412
+ // from each input list, each combination being itself wrapped in a `types `. For
415
413
// example:
416
414
417
415
// >
@@ -421,12 +419,12 @@ struct definition<comparison, T, U> {
421
419
static_assert (
422
420
std::is_same_v<
423
421
product<
424
- mp_list <int , double >,
425
- mp_list <int , double , float >
422
+ types <int , double >,
423
+ types <int , double , float >
426
424
>,
427
- mp_list <
428
- mp_list <int , int >, mp_list <int , double >, mp_list <int , float >,
429
- mp_list <double , int >, mp_list <double , double >, mp_list <double , float >
425
+ types <
426
+ types <int , int >, types <int , double >, types <int , float >,
427
+ types <double , int >, types <double , double >, types <double , float >
430
428
>
431
429
>);
432
430
@@ -456,9 +454,9 @@ use_classes<
456
454
use_definitions<
457
455
definition,
458
456
product<
459
- mp_list <addition, subtraction, comparison>,
460
- mp_list <int , double >,
461
- mp_list <int , double >
457
+ types <addition, subtraction, comparison>,
458
+ types <int , double >,
459
+ types <int , double >
462
460
>
463
461
> YOMM2_GENSYM;
464
462
@@ -506,7 +504,7 @@ BOOST_AUTO_TEST_CASE(test_vectors) {
506
504
// ## Writing a user-friendly instantiation function
507
505
508
506
// Now we have everything we need to write a single template that allows users
509
- // to initialize the library for the mp_list they need. For that we use
507
+ // to initialize the library for the types they need. For that we use
510
508
// `std::tuple` to lump teh registration object together:
511
509
512
510
// >
@@ -523,9 +521,9 @@ using use_vector_library = std::tuple<
523
521
use_definitions<
524
522
definition,
525
523
product<
526
- mp_list <addition, subtraction, comparison>,
527
- mp_list <NumericTypes...>,
528
- mp_list <NumericTypes...>
524
+ types <addition, subtraction, comparison>,
525
+ types <NumericTypes...>,
526
+ types <NumericTypes...>
529
527
>
530
528
>
531
529
>;
@@ -535,7 +533,7 @@ using use_vector_library = std::tuple<
535
533
// md<
536
534
537
535
// All the user of the library needs to do now is to create an instance (object)
538
- // of `use_vector_library`, instantiated with the required mp_list :
536
+ // of `use_vector_library`, instantiated with the required types :
539
537
540
538
// >
541
539
@@ -606,7 +604,7 @@ use_vector_library<int, double> init_vectors;
606
604
607
605
// For brevity, we will consider only ordinary (i.e. non-square), square and
608
606
// symmetric matrices. Also, we will omit all maths and storage management, to
609
- // focus on dealing with mp_list .
607
+ // focus on dealing with types .
610
608
611
609
// Here is the implementation of these classes, and the intermediary abstract
612
610
// classes:
@@ -702,7 +700,7 @@ struct symmetric : any_symmetric<T> {
702
700
// importantly, better interfaces. For example, square matrices have a
703
701
// determinant, which ordinary matrices do not have. Also, type errors can be
704
702
// diagnosed by the compiler. However, compile-time specialization is possible
705
- // only if the mp_list of the matrices is known in advance. It may not always be
703
+ // only if the types of the matrices is known in advance. It may not always be
706
704
// the case.
707
705
708
706
// Thus, as library designers, we face a dilemma: which users to serve best?
@@ -909,7 +907,7 @@ auto operator~(const handle<Matrix<T>>& m) {
909
907
// 1. `Matrix` is actually one of our `matrix` templates; without (1), *any*
910
908
// template would match.
911
909
// 2. `Matrix<T>` is abstract; without (2), we would have an ambiguity with our
912
- // own `operator~` defined above for concrete matrix mp_list .
910
+ // own `operator~` defined above for concrete matrix types .
913
911
914
912
// C++20 concepts offer a much cleaner solution for taming template
915
913
// instantiations.
@@ -919,7 +917,7 @@ auto operator~(const handle<Matrix<T>>& m) {
919
917
// methods, e.g. `negate`. For that we use a templatized definition container
920
918
// called `unary_definition`. We want to instantiate it for every combination of
921
919
// method template, abstract base class, concrete implementation of the abstract
922
- // class, and this for the required numeric mp_list . E.g.:
920
+ // class, and this for the required numeric types . E.g.:
923
921
// - `transpose<any<int>>`, `any<int>`, `ordinary<int>`
924
922
// - `transpose<any<int>>`, `any_square`, `square`
925
923
// - `transpose<any<int>>`, `any_square`, `symmetrical`
@@ -939,22 +937,22 @@ auto operator~(const handle<Matrix<T>>& m) {
939
937
// M = { unary method templates: transpose, negate, etc }
940
938
// A = { abstract class templates }
941
939
// C = { concrete class templates }
942
- // T = { required numeric mp_list }
940
+ // T = { required numeric types }
943
941
// ```
944
942
945
943
// ...and selecting the combinations that satisfy the condition:
946
944
// - `A<T>` is a base of `C<T>`
947
945
948
946
// This time, we need to make a Cartesian product that involves templates as
949
- // well as mp_list . For this, YOMM2 provides two constructs:
947
+ // well as types . For this, YOMM2 provides two constructs:
950
948
// - `template_<template<typename...> typename>` wraps a template in a type. It
951
949
// contains a nested template `fn<typename...Ts>`, which applies the original
952
950
// template to `Ts...`. Thus we have the identity:
953
951
// ```
954
952
// template_<F>::template fn<Ts...> = F<Ts...>
955
953
// ```
956
954
// - `templates<template<typename...> typename...>` wraps a list of templates in
957
- // a `mp_list ` list of `template_`s.
955
+ // a `types ` list of `template_`s.
958
956
959
957
// We can now implement `unary_definition`:
960
958
@@ -1032,27 +1030,27 @@ use_definitions<
1032
1030
unary_definition,
1033
1031
product<
1034
1032
templates<transpose>, abstract_matrix_templates,
1035
- concrete_matrix_templates, mp_list <double , int >>>
1033
+ concrete_matrix_templates, types <double , int >>>
1036
1034
YOMM2_GENSYM;
1037
1035
// >
1038
1036
1039
1037
// md<
1040
1038
1041
1039
// We must not forget to register all the matrix classes, for both numeric
1042
- // mp_list . For that, we can use another YOMM2 helper: `apply_product`. It takes a
1043
- // `templates` list, and any number of `mp_list ` list; forms the Cartesian
1040
+ // types . For that, we can use another YOMM2 helper: `apply_product`. It takes a
1041
+ // `templates` list, and any number of `types ` list; forms the Cartesian
1044
1042
// product; and, for each resulting combination, applies the first element - a
1045
- // template - to the other elements. The result is a `mp_list ` list of template
1043
+ // template - to the other elements. The result is a `types ` list of template
1046
1044
// instantiations.
1047
1045
1048
1046
// We saw that `use_classes` takes a list of classes. It also works with a
1049
- // list of `mp_list ` lists. We can thus inject the result of `apply_product` into
1047
+ // list of `types ` lists. We can thus inject the result of `apply_product` into
1050
1048
// `use_classes`:
1051
1049
1052
1050
// >
1053
1051
1054
1052
// code<
1055
- YOMM2_STATIC (use_classes<apply_product<matrix_templates, mp_list <double , int >>>);
1053
+ YOMM2_STATIC (use_classes<apply_product<matrix_templates, types <double , int >>>);
1056
1054
// >
1057
1055
1058
1056
#endif
@@ -1088,12 +1086,12 @@ BOOST_AUTO_TEST_CASE(test_dynamic_transpose) {
1088
1086
// `any_square<double>`.
1089
1087
1090
1088
// Fortunately, we can leverage the static `operator+` to deduce the return type
1091
- // of additions that involve one or two abstract mp_list . This is what the nested
1092
- // `abstract_type` and `concrete_type` aliases are for. We can convert the mp_list
1089
+ // of additions that involve one or two abstract types . This is what the nested
1090
+ // `abstract_type` and `concrete_type` aliases are for. We can convert the types
1093
1091
// of the arguments to their nearest concrete type: for a
1094
1092
// `any_symmetric<double>`, it is a `symmetric<double>`; for a `square<double>`,
1095
1093
// it is `square<double>`. Then we can "pretend" to add two handles to objects
1096
- // of the two mp_list , and extract the result's type using `decltype`. And
1094
+ // of the two types , and extract the result's type using `decltype`. And
1097
1095
// finally, we convert that type to its abstract base class, using
1098
1096
// `abstract_type`.
1099
1097
@@ -1182,7 +1180,7 @@ auto operator+(const handle<M1>& a, const handle<M2>& b) {
1182
1180
// M = { unary method templates: transpose, negate, etc }
1183
1181
// A1, A2 = { abstract class templates }
1184
1182
// C1, C2 = { concrete class templates }
1185
- // T1, T2 = { required numeric mp_list }
1183
+ // T1, T2 = { required numeric types }
1186
1184
// ```
1187
1185
1188
1186
// ...and selecting the combinations that satisfy the condition:
@@ -1287,8 +1285,8 @@ use_definitions<
1287
1285
binary_definition,
1288
1286
product<
1289
1287
templates<add>, abstract_matrix_templates, concrete_matrix_templates,
1290
- mp_list <double , int >, abstract_matrix_templates,
1291
- concrete_matrix_templates, mp_list <double , int >>>
1288
+ types <double , int >, abstract_matrix_templates,
1289
+ concrete_matrix_templates, types <double , int >>>
1292
1290
YOMM2_GENSYM;
1293
1291
// >
1294
1292
@@ -1326,7 +1324,7 @@ BOOST_AUTO_TEST_CASE(test_dynamic_operations) {
1326
1324
// Now we need to create a mechanism that enable users to instantiate just the
1327
1325
// method definitions they want. This is more complicated than for the vector
1328
1326
// library, because users need to be able to select from three sets: the
1329
- // underlying numeric mp_list , the matrix mp_list , and the methods. For example:
1327
+ // underlying numeric types , the matrix types , and the methods. For example:
1330
1328
1331
1329
// >
1332
1330
@@ -1338,11 +1336,11 @@ BOOST_AUTO_TEST_CASE(test_dynamic_operations) {
1338
1336
// use_polymorphic_matrices<>::with<add, transpose> YOMM2_GENSYM; // 5
1339
1337
// ```
1340
1338
1341
- // 1. all matrix mp_list of `double`, with all operations
1342
- // 2. all matrix mp_list of `int` and `double`, with all operations
1339
+ // 1. all matrix types of `double`, with all operations
1340
+ // 2. all matrix types of `int` and `double`, with all operations
1343
1341
// 3. square and symmetric matrices of `double`, with all operations
1344
1342
// 4. square and symmetric matrices of `int` and `double`, polymorphic addition only
1345
- // 5. all matrix mp_list of `double`, with all operations
1343
+ // 5. all matrix types of `double`, with all operations
1346
1344
1347
1345
// Let's implement this. First we need a few helpers.
1348
1346
@@ -1424,17 +1422,17 @@ struct definition_traits<add> : binary_definition_traits<add> {};
1424
1422
1425
1423
template <template <typename > typename ... Ms>
1426
1424
struct use_polymorphic_matrices {
1427
- using abstract_matrix_templates = mp_list <
1425
+ using abstract_matrix_templates = types <
1428
1426
typename template_of<typename Ms<double >::abstract_type>::type...>;
1429
1427
using concrete_matrix_templates = templates<Ms...>;
1430
1428
template <typename ... Ts>
1431
1429
struct of {
1432
- using numeric_types = mp_list <Ts...>;
1430
+ using numeric_types = types <Ts...>;
1433
1431
template <template <typename ...> typename ... Ops>
1434
1432
struct with
1435
1433
: use_classes<
1436
- apply_product<abstract_matrix_templates, mp_list <Ts...>>,
1437
- apply_product<concrete_matrix_templates, mp_list <Ts...>>>,
1434
+ apply_product<abstract_matrix_templates, types <Ts...>>,
1435
+ apply_product<concrete_matrix_templates, types <Ts...>>>,
1438
1436
definition_traits<Ops>::template fn<
1439
1437
abstract_matrix_templates, concrete_matrix_templates,
1440
1438
numeric_types>... {};
0 commit comments