From 1925d4dcc65df310c7a6677ff2e9520c002fc031 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Wed, 22 Apr 2020 21:06:56 +0100 Subject: [PATCH] Squashed 'externals/mp/' changes from 29cb5588d..649fde1e8 649fde1e8 typelist: Add drop 5efe868da travis: Drop GCC 7 from CI c3f890f17 Update to use new metavalue types c4dd1c9b9 metavalue: Add some common operations 7da45c71b Remove unnecessary public keyword for struct inheritance 287d8e7ec Correct typos in file headers git-subtree-dir: externals/mp git-subtree-split: 649fde1e814f9ce5b04d7ddeb940244d9f63cb2f --- .travis.yml | 3 - README.md | 26 +++++--- include/mp/metafunction/apply.h | 2 +- include/mp/metavalue/bit_and.h | 20 +++++++ include/mp/metavalue/bit_not.h | 20 +++++++ include/mp/metavalue/bit_or.h | 20 +++++++ include/mp/metavalue/bit_xor.h | 20 +++++++ include/mp/metavalue/conjunction.h | 43 ++++++++++++++ include/mp/metavalue/disjunction.h | 43 ++++++++++++++ include/mp/metavalue/logic_and.h | 20 +++++++ include/mp/metavalue/logic_if.h | 21 +++++++ include/mp/metavalue/logic_not.h | 20 +++++++ include/mp/metavalue/logic_or.h | 20 +++++++ include/mp/metavalue/product.h | 20 +++++++ include/mp/metavalue/sum.h | 20 +++++++ include/mp/metavalue/value.h | 31 ++++++++++ include/mp/traits/function_info.h | 8 +-- include/mp/traits/is_instance_of_template.h | 6 +- include/mp/typelist/contains.h | 6 +- include/mp/typelist/drop.h | 34 +++++++++++ tests/metavalue_tests.h | 66 +++++++++++++++++++++ tests/typelist_tests.h | 15 ++++- 22 files changed, 460 insertions(+), 24 deletions(-) create mode 100644 include/mp/metavalue/bit_and.h create mode 100644 include/mp/metavalue/bit_not.h create mode 100644 include/mp/metavalue/bit_or.h create mode 100644 include/mp/metavalue/bit_xor.h create mode 100644 include/mp/metavalue/conjunction.h create mode 100644 include/mp/metavalue/disjunction.h create mode 100644 include/mp/metavalue/logic_and.h create mode 100644 include/mp/metavalue/logic_if.h create mode 100644 include/mp/metavalue/logic_not.h create mode 100644 include/mp/metavalue/logic_or.h create mode 100644 include/mp/metavalue/product.h create mode 100644 include/mp/metavalue/sum.h create mode 100644 include/mp/metavalue/value.h create mode 100644 include/mp/typelist/drop.h diff --git a/.travis.yml b/.travis.yml index e864bf47..8d77227c 100644 --- a/.travis.yml +++ b/.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/README.md b/README.md index f4c0e5de..21617870 100644 --- a/README.md +++ b/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/include/mp/metafunction/apply.h b/include/mp/metafunction/apply.h index 6ccf1a5f..3ab0d960 100644 --- a/include/mp/metafunction/apply.h +++ b/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/include/mp/metavalue/bit_and.h b/include/mp/metavalue/bit_and.h new file mode 100644 index 00000000..3124266a --- /dev/null +++ b/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/include/mp/metavalue/bit_not.h b/include/mp/metavalue/bit_not.h new file mode 100644 index 00000000..4aa7d846 --- /dev/null +++ b/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/include/mp/metavalue/bit_or.h b/include/mp/metavalue/bit_or.h new file mode 100644 index 00000000..6e39d227 --- /dev/null +++ b/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/include/mp/metavalue/bit_xor.h b/include/mp/metavalue/bit_xor.h new file mode 100644 index 00000000..6b0463d9 --- /dev/null +++ b/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/include/mp/metavalue/conjunction.h b/include/mp/metavalue/conjunction.h new file mode 100644 index 00000000..7038b27f --- /dev/null +++ b/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/include/mp/metavalue/disjunction.h b/include/mp/metavalue/disjunction.h new file mode 100644 index 00000000..b5f5c3b5 --- /dev/null +++ b/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/include/mp/metavalue/logic_and.h b/include/mp/metavalue/logic_and.h new file mode 100644 index 00000000..5e4a1f73 --- /dev/null +++ b/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/include/mp/metavalue/logic_if.h b/include/mp/metavalue/logic_if.h new file mode 100644 index 00000000..a548d8ab --- /dev/null +++ b/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/include/mp/metavalue/logic_not.h b/include/mp/metavalue/logic_not.h new file mode 100644 index 00000000..b2cf79c4 --- /dev/null +++ b/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/include/mp/metavalue/logic_or.h b/include/mp/metavalue/logic_or.h new file mode 100644 index 00000000..030b4995 --- /dev/null +++ b/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/include/mp/metavalue/product.h b/include/mp/metavalue/product.h new file mode 100644 index 00000000..99a679ce --- /dev/null +++ b/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/include/mp/metavalue/sum.h b/include/mp/metavalue/sum.h new file mode 100644 index 00000000..02dbfef7 --- /dev/null +++ b/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/include/mp/metavalue/value.h b/include/mp/metavalue/value.h new file mode 100644 index 00000000..e57df6f7 --- /dev/null +++ b/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/include/mp/traits/function_info.h b/include/mp/traits/function_info.h index a2344cfe..7f5a9dbf 100644 --- a/include/mp/traits/function_info.h +++ b/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/include/mp/traits/is_instance_of_template.h b/include/mp/traits/is_instance_of_template.h index 3299e8c3..d30bba57 100644 --- a/include/mp/traits/is_instance_of_template.h +++ b/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