diff --git a/externals/mp/.travis.yml b/externals/mp/.travis.yml index e864bf47..8d77227c 100644 --- a/externals/mp/.travis.yml +++ b/externals/mp/.travis.yml @@ -5,9 +5,6 @@ matrix: - compiler: clang env: CXX=clang dist: bionic - - compiler: g++-7 - env: CXX=g++-7 - dist: bionic - compiler: g++-8 env: CXX=g++-8 addons: diff --git a/externals/mp/README.md b/externals/mp/README.md index f4c0e5de..21617870 100644 --- a/externals/mp/README.md +++ b/externals/mp/README.md @@ -53,14 +53,15 @@ A metavalue is a type of template `std::integral_constant`. ### Constants -* [`std::true_type`](https://en.cppreference.com/w/cpp/types/integral_constant) -* [`std::false_type`](https://en.cppreference.com/w/cpp/types/integral_constant) +* mp::true_type: Aliases to [`std::true_type`](https://en.cppreference.com/w/cpp/types/integral_constant) +* mp::false_type: Aliases to [`mp::false_type`](https://en.cppreference.com/w/cpp/types/integral_constant) ### Constructor -* [`std::integral_constant`](https://en.cppreference.com/w/cpp/types/integral_constant) -* [`std::bool_constant`](https://en.cppreference.com/w/cpp/types/integral_constant) -* `mp::lift_value`: Lifts a value to become a metavalue +* mp::value: Aliases to [`std::integral_constant`](https://en.cppreference.com/w/cpp/types/integral_constant) +* mp::bool_value: Aliases to [`std::bool_constant`](https://en.cppreference.com/w/cpp/types/integral_constant) +* mp::size_value: Constructs a metavalue with value of type std::size_t +* `mp::lift_value`: Lifts a value of any arbitrary type to become a metavalue ### Conversions @@ -69,9 +70,18 @@ A metavalue is a type of template `std::integral_constant`. ### Operations * `mp::value_equal`: Compares value equality, ignores type. Use `std::is_same` for strict comparison. -* [`std::negation`](https://en.cppreference.com/w/cpp/types/negation) -* [`std::conjunction`](https://en.cppreference.com/w/cpp/types/conjunction) -* [`std::disjunction`](https://en.cppreference.com/w/cpp/types/disjunction) +* `mp::logic_if`: Like std::conditional but has a bool metavalue as first argument. +* `mp::bit_not`: Bitwise not +* `mp::bit_and`: Bitwise and +* `mp::bit_or`: Bitwise or +* `mp::bit_xor`: Bitwise xor +* `mp::logic_not`: Logical not +* `mp::logic_and`: Logical conjunction (no short circuiting, always results in a mp:bool_value) +* `mp::logic_or`: Logical disjunction (no short circuiting, always results in a mp:bool_value) +* `mp::conjunction`: Logical conjunction (with short circuiting, preserves type) +* `mp::disjunction`: Logical disjunction (with short circuiting, preserves type) +* `mp::sum`: Sum of values +* `mp::product`: Product of values `metafunction` -------------- diff --git a/externals/mp/include/mp/metafunction/apply.h b/externals/mp/include/mp/metafunction/apply.h index 6ccf1a5f..3ab0d960 100644 --- a/externals/mp/include/mp/metafunction/apply.h +++ b/externals/mp/include/mp/metafunction/apply.h @@ -1,4 +1,4 @@ -/* Ehis file is part of the mp project. +/* This file is part of the mp project. * Copyright (c) 2017 MerryMage * SPDX-License-Identifier: 0BSD */ diff --git a/externals/mp/include/mp/metavalue/bit_and.h b/externals/mp/include/mp/metavalue/bit_and.h new file mode 100644 index 00000000..3124266a --- /dev/null +++ b/externals/mp/include/mp/metavalue/bit_and.h @@ -0,0 +1,20 @@ +/* This file is part of the mp project. + * Copyright (c) 2020 MerryMage + * SPDX-License-Identifier: 0BSD + */ + +#pragma once + +#include + +namespace mp { + +/// Bitwise and of metavalues Vs +template +using bit_and = lift_value<(Vs::value & ...)>; + +/// Bitwise and of metavalues Vs +template +constexpr auto bit_and_v = (Vs::value & ...); + +} // namespace mp diff --git a/externals/mp/include/mp/metavalue/bit_not.h b/externals/mp/include/mp/metavalue/bit_not.h new file mode 100644 index 00000000..4aa7d846 --- /dev/null +++ b/externals/mp/include/mp/metavalue/bit_not.h @@ -0,0 +1,20 @@ +/* This file is part of the mp project. + * Copyright (c) 2020 MerryMage + * SPDX-License-Identifier: 0BSD + */ + +#pragma once + +#include + +namespace mp { + +/// Bitwise not of metavalue V +template +using bit_not = lift_value<~V::value>; + +/// Bitwise not of metavalue V +template +constexpr auto bit_not_v = ~V::value; + +} // namespace mp diff --git a/externals/mp/include/mp/metavalue/bit_or.h b/externals/mp/include/mp/metavalue/bit_or.h new file mode 100644 index 00000000..6e39d227 --- /dev/null +++ b/externals/mp/include/mp/metavalue/bit_or.h @@ -0,0 +1,20 @@ +/* This file is part of the mp project. + * Copyright (c) 2020 MerryMage + * SPDX-License-Identifier: 0BSD + */ + +#pragma once + +#include + +namespace mp { + +/// Bitwise or of metavalues Vs +template +using bit_or = lift_value<(Vs::value | ...)>; + +/// Bitwise or of metavalues Vs +template +constexpr auto bit_or_v = (Vs::value | ...); + +} // namespace mp diff --git a/externals/mp/include/mp/metavalue/bit_xor.h b/externals/mp/include/mp/metavalue/bit_xor.h new file mode 100644 index 00000000..6b0463d9 --- /dev/null +++ b/externals/mp/include/mp/metavalue/bit_xor.h @@ -0,0 +1,20 @@ +/* This file is part of the mp project. + * Copyright (c) 2020 MerryMage + * SPDX-License-Identifier: 0BSD + */ + +#pragma once + +#include + +namespace mp { + +/// Bitwise xor of metavalues Vs +template +using bit_xor = lift_value<(Vs::value ^ ...)>; + +/// Bitwise xor of metavalues Vs +template +constexpr auto bit_xor_v = (Vs::value ^ ...); + +} // namespace mp diff --git a/externals/mp/include/mp/metavalue/conjunction.h b/externals/mp/include/mp/metavalue/conjunction.h new file mode 100644 index 00000000..7038b27f --- /dev/null +++ b/externals/mp/include/mp/metavalue/conjunction.h @@ -0,0 +1,43 @@ +/* This file is part of the mp project. + * Copyright (c) 2020 MerryMage + * SPDX-License-Identifier: 0BSD + */ + +#pragma once + +#include +#include + +namespace mp { + +namespace detail { + +template +struct conjunction_impl; + +template<> +struct conjunction_impl<> { + using type = false_type; +}; + +template +struct conjunction_impl { + using type = V; +}; + +template +struct conjunction_impl { + using type = logic_if::type, V1>; +}; + +} // namespace detail + +/// Conjunction of metavalues Vs with short-circuiting and type preservation. +template +using conjunction = typename detail::conjunction_impl::type; + +/// Conjunction of metavalues Vs with short-circuiting and type preservation. +template +constexpr auto conjunction_v = conjunction::value; + +} // namespace mp diff --git a/externals/mp/include/mp/metavalue/disjunction.h b/externals/mp/include/mp/metavalue/disjunction.h new file mode 100644 index 00000000..b5f5c3b5 --- /dev/null +++ b/externals/mp/include/mp/metavalue/disjunction.h @@ -0,0 +1,43 @@ +/* This file is part of the mp project. + * Copyright (c) 2020 MerryMage + * SPDX-License-Identifier: 0BSD + */ + +#pragma once + +#include +#include + +namespace mp { + +namespace detail { + +template +struct disjunction_impl; + +template<> +struct disjunction_impl<> { + using type = false_type; +}; + +template +struct disjunction_impl { + using type = V; +}; + +template +struct disjunction_impl { + using type = logic_if::type>; +}; + +} // namespace detail + +/// Disjunction of metavalues Vs with short-circuiting and type preservation. +template +using disjunction = typename detail::disjunction_impl::type; + +/// Disjunction of metavalues Vs with short-circuiting and type preservation. +template +constexpr auto disjunction_v = disjunction::value; + +} // namespace mp diff --git a/externals/mp/include/mp/metavalue/logic_and.h b/externals/mp/include/mp/metavalue/logic_and.h new file mode 100644 index 00000000..5e4a1f73 --- /dev/null +++ b/externals/mp/include/mp/metavalue/logic_and.h @@ -0,0 +1,20 @@ +/* This file is part of the mp project. + * Copyright (c) 2020 MerryMage + * SPDX-License-Identifier: 0BSD + */ + +#pragma once + +#include + +namespace mp { + +/// Logical conjunction of metavalues Vs without short-circuiting or type presevation. +template +using logic_and = bool_value<(true && ... && Vs::value)>; + +/// Logical conjunction of metavalues Vs without short-circuiting or type presevation. +template +constexpr bool logic_and_v = (true && ... && Vs::value); + +} // namespace mp diff --git a/externals/mp/include/mp/metavalue/logic_if.h b/externals/mp/include/mp/metavalue/logic_if.h new file mode 100644 index 00000000..a548d8ab --- /dev/null +++ b/externals/mp/include/mp/metavalue/logic_if.h @@ -0,0 +1,21 @@ +/* This file is part of the mp project. + * Copyright (c) 2020 MerryMage + * SPDX-License-Identifier: 0BSD + */ + +#pragma once + +#include +#include + +namespace mp { + +/// Conditionally select between types T and F based on boolean metavalue V +template +using logic_if = std::conditional_t; + +/// Conditionally select between metavalues T and F based on boolean metavalue V +template +constexpr auto logic_if_v = logic_if::value; + +} // namespace mp diff --git a/externals/mp/include/mp/metavalue/logic_not.h b/externals/mp/include/mp/metavalue/logic_not.h new file mode 100644 index 00000000..b2cf79c4 --- /dev/null +++ b/externals/mp/include/mp/metavalue/logic_not.h @@ -0,0 +1,20 @@ +/* This file is part of the mp project. + * Copyright (c) 2020 MerryMage + * SPDX-License-Identifier: 0BSD + */ + +#pragma once + +#include + +namespace mp { + +/// Logical negation of metavalue V. +template +using logic_not = bool_value; + +/// Logical negation of metavalue V. +template +constexpr bool logic_not_v = !bool(V::value); + +} // namespace mp diff --git a/externals/mp/include/mp/metavalue/logic_or.h b/externals/mp/include/mp/metavalue/logic_or.h new file mode 100644 index 00000000..030b4995 --- /dev/null +++ b/externals/mp/include/mp/metavalue/logic_or.h @@ -0,0 +1,20 @@ +/* This file is part of the mp project. + * Copyright (c) 2020 MerryMage + * SPDX-License-Identifier: 0BSD + */ + +#pragma once + +#include + +namespace mp { + +/// Logical disjunction of metavalues Vs without short-circuiting or type presevation. +template +using logic_or = bool_value<(false || ... || Vs::value)>; + +/// Logical disjunction of metavalues Vs without short-circuiting or type presevation. +template +constexpr bool logic_or_v = (false || ... || Vs::value); + +} // namespace mp diff --git a/externals/mp/include/mp/metavalue/product.h b/externals/mp/include/mp/metavalue/product.h new file mode 100644 index 00000000..99a679ce --- /dev/null +++ b/externals/mp/include/mp/metavalue/product.h @@ -0,0 +1,20 @@ +/* This file is part of the mp project. + * Copyright (c) 2020 MerryMage + * SPDX-License-Identifier: 0BSD + */ + +#pragma once + +#include + +namespace mp { + +/// Product of metavalues Vs +template +using product = lift_value<(Vs::value * ...)>; + +/// Product of metavalues Vs +template +constexpr auto product_v = (Vs::value * ...); + +} // namespace mp diff --git a/externals/mp/include/mp/metavalue/sum.h b/externals/mp/include/mp/metavalue/sum.h new file mode 100644 index 00000000..02dbfef7 --- /dev/null +++ b/externals/mp/include/mp/metavalue/sum.h @@ -0,0 +1,20 @@ +/* This file is part of the mp project. + * Copyright (c) 2020 MerryMage + * SPDX-License-Identifier: 0BSD + */ + +#pragma once + +#include + +namespace mp { + +/// Sum of metavalues Vs +template +using sum = lift_value<(Vs::value + ...)>; + +/// Sum of metavalues Vs +template +constexpr auto sum_v = (Vs::value + ...); + +} // namespace mp diff --git a/externals/mp/include/mp/metavalue/value.h b/externals/mp/include/mp/metavalue/value.h new file mode 100644 index 00000000..e57df6f7 --- /dev/null +++ b/externals/mp/include/mp/metavalue/value.h @@ -0,0 +1,31 @@ +/* This file is part of the mp project. + * Copyright (c) 2020 MerryMage + * SPDX-License-Identifier: 0BSD + */ + +#pragma once + +#include +#include + +namespace mp { + +/// A metavalue (of type VT and value v). +template +using value = std::integral_constant; + +/// A metavalue of type std::size_t (and value v). +template +using size_value = value; + +/// A metavalue of type bool (and value v). (Aliases to std::bool_constant.) +template +using bool_value = value; + +/// true metavalue (Aliases to std::true_type). +using true_type = bool_value; + +/// false metavalue (Aliases to std::false_type). +using false_type = bool_value; + +} // namespace mp diff --git a/externals/mp/include/mp/traits/function_info.h b/externals/mp/include/mp/traits/function_info.h index a2344cfe..7f5a9dbf 100644 --- a/externals/mp/include/mp/traits/function_info.h +++ b/externals/mp/include/mp/traits/function_info.h @@ -13,7 +13,7 @@ namespace mp { template -struct function_info : public function_info {}; +struct function_info : function_info {}; template struct function_info { @@ -31,15 +31,15 @@ struct function_info { }; template -struct function_info : public function_info {}; +struct function_info : function_info {}; template -struct function_info : public function_info { +struct function_info : function_info { using class_type = C; }; template -struct function_info : public function_info { +struct function_info : function_info { using class_type = C; }; diff --git a/externals/mp/include/mp/traits/is_instance_of_template.h b/externals/mp/include/mp/traits/is_instance_of_template.h index 3299e8c3..d30bba57 100644 --- a/externals/mp/include/mp/traits/is_instance_of_template.h +++ b/externals/mp/include/mp/traits/is_instance_of_template.h @@ -5,16 +5,16 @@ #pragma once -#include +#include namespace mp { /// Is type T an instance of template class C? template