Skip to content

Commit

Permalink
Add mpl::Value meta-programming type; comparison operator support det…
Browse files Browse the repository at this point in the history
…ection type traits and concepts; general operator support detection type traits and concepts; std supplemental type traits and concepts;
  • Loading branch information
braxtons12 committed Jan 29, 2024
1 parent 024d9e5 commit 36d1c72
Show file tree
Hide file tree
Showing 14 changed files with 1,236 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ IndentCaseLabels: true
IndentExternBlock: Indent
IndentGotoLabels: true
IndentPPDirectives: BeforeHash
IndentRequires: false
IndentRequiresClause: true
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
Expand Down
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,19 @@ set(HYPERION_PLATFORM_INCLUDE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/include/hyperion"
)
set(HYPERION_PLATFORM_HEADERS
"${HYPERION_PLATFORM_INCLUDE_PATH}/mpl/concepts.h"
"${HYPERION_PLATFORM_INCLUDE_PATH}/mpl/index.h"
"${HYPERION_PLATFORM_INCLUDE_PATH}/mpl/list.h"
"${HYPERION_PLATFORM_INCLUDE_PATH}/mpl/type_traits.h"
"${HYPERION_PLATFORM_INCLUDE_PATH}/mpl/value.h"
"${HYPERION_PLATFORM_INCLUDE_PATH}/mpl/algorithms.h"
"${HYPERION_PLATFORM_INCLUDE_PATH}/mpl/algorithms/all_of.h"
"${HYPERION_PLATFORM_INCLUDE_PATH}/mpl/concepts.h"
"${HYPERION_PLATFORM_INCLUDE_PATH}/mpl/concepts/comparable.h"
"${HYPERION_PLATFORM_INCLUDE_PATH}/mpl/concepts/operator_able.h"
"${HYPERION_PLATFORM_INCLUDE_PATH}/mpl/concepts/std_supplemental.h"
"${HYPERION_PLATFORM_INCLUDE_PATH}/mpl/type_traits.h"
"${HYPERION_PLATFORM_INCLUDE_PATH}/mpl/type_traits/is_comparable.h"
"${HYPERION_PLATFORM_INCLUDE_PATH}/mpl/type_traits/is_operator_able.h"
"${HYPERION_PLATFORM_INCLUDE_PATH}/mpl/type_traits/std_supplemental.h"
)

add_library(hyperion_mpl INTERFACE)
Expand Down
7 changes: 7 additions & 0 deletions include/hyperion/mpl/algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
/// SOFTWARE.

#ifndef HYPERION_MPL_ALGORITHMS_H
#define HYPERION_MPL_ALGORITHMS_H

#include <hyperion/mpl/algorithms/all_of.h>

#endif // HYPERION_MPL_ALGORITHMS_H
8 changes: 8 additions & 0 deletions include/hyperion/mpl/concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
/// SOFTWARE.

#ifndef HYPERION_MPL_CONCEPTS_H
#define HYPERION_MPL_CONCEPTS_H

#include <hyperion/mpl/concepts/comparable.h>
#include <hyperion/mpl/concepts/operator_able.h>
#include <hyperion/mpl/concepts/std_supplemental.h>

#endif // HYPERION_MPL_CONCEPTS_H
113 changes: 113 additions & 0 deletions include/hyperion/mpl/concepts/comparable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/// @file comparable.h
/// @author Braxton Salyer <[email protected]>
/// @brief Meta-programming C++20 concepts to determine if two types are comparable
/// in various ways
/// @version 0.1
/// @date 2024-01-27
///
/// MIT License
/// @copyright Copyright (c) 2024 Braxton Salyer <[email protected]>
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to
/// deal in the Software without restriction, including without limitation the
/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
/// sell copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
/// IN THE SOFTWARE.

#ifndef HYPERION_MPL_CONCEPTS_COMPARABLE_H
#define HYPERION_MPL_CONCEPTS_COMPARABLE_H

#include <hyperion/mpl/type_traits/is_comparable.h>

namespace hyperion::mpl::concepts {

template<typename TLhs, typename TRhs>
concept EqualityComparable = type_traits::is_equality_comparable_v<TLhs, TRhs>;

template<typename TLhs, typename TRhs>
concept InequalityComparable = type_traits::is_inequality_comparable_v<TLhs, TRhs>;

template<typename TLhs, typename TRhs>
concept LessThanComparable = type_traits::is_less_than_comparable_v<TLhs, TRhs>;

template<typename TLhs, typename TRhs>
concept LessThanOrEqualComparable = type_traits::is_less_than_or_equal_comparable_v<TLhs, TRhs>;

template<typename TLhs, typename TRhs>
concept GreaterThanComparable = type_traits::is_greater_than_comparable_v<TLhs, TRhs>;

template<typename TLhs, typename TRhs>
concept GreaterThanOrEqualComparable
= type_traits::is_greater_than_or_equal_comparable_v<TLhs, TRhs>;

template<typename TLhs, typename TRhs>
concept ThreeWayComparable = type_traits::is_three_way_comparable_v<TLhs, TRhs>;

namespace _test {

struct not_comparable { };

static_assert(EqualityComparable<int, int>,
"hyperion::mpl::concepts::EqualityComparable test case 1 failing");
static_assert(EqualityComparable<int, double>,
"hyperion::mpl::concepts::EqualityComparable test case 2 failing");
static_assert(!EqualityComparable<int, not_comparable>,
"hyperion::mpl::concepts::EqualityComparable test case 3 failing");

static_assert(InequalityComparable<int, int>,
"hyperion::mpl::concepts::InequalityComparable test case 1 failing");
static_assert(InequalityComparable<int, double>,
"hyperion::mpl::concepts::InequalityComparable test case 2 failing");
static_assert(!InequalityComparable<int, not_comparable>,
"hyperion::mpl::concepts::InequalityComparable test case 3 failing");

static_assert(LessThanComparable<int, int>,
"hyperion::mpl::concepts::LessThanComparable test case 1 failing");
static_assert(LessThanComparable<int, double>,
"hyperion::mpl::concepts::LessThanComparable test case 2 failing");
static_assert(!LessThanComparable<int, not_comparable>,
"hyperion::mpl::concepts::LessThanComparable test case 3 failing");

static_assert(LessThanOrEqualComparable<int, int>,
"hyperion::mpl::concepts::LessThanOrEqualComparable test case 1 failing");
static_assert(LessThanOrEqualComparable<int, double>,
"hyperion::mpl::concepts::LessThanOrEqualComparable test case 2 failing");
static_assert(!LessThanOrEqualComparable<int, not_comparable>,
"hyperion::mpl::concepts::LessThanOrEqualComparable test case 3 failing");

static_assert(GreaterThanComparable<int, int>,
"hyperion::mpl::concepts::GreaterThanComparable test case 1 failing");
static_assert(GreaterThanComparable<int, double>,
"hyperion::mpl::concepts::GreaterThanComparable test case 2 failing");
static_assert(!GreaterThanComparable<int, not_comparable>,
"hyperion::mpl::concepts::GreaterThanComparable test case 3 failing");

static_assert(GreaterThanOrEqualComparable<int, int>,
"hyperion::mpl::concepts::GreaterThanOrEqualComparable test case 1 failing");
static_assert(GreaterThanOrEqualComparable<int, double>,
"hyperion::mpl::concepts::GreaterThanOrEqualComparable test case 2 failing");
static_assert(!GreaterThanOrEqualComparable<int, not_comparable>,
"hyperion::mpl::concepts::GreaterThanOrEqualComparable test case 3 failing");

static_assert(ThreeWayComparable<int, int>,
"hyperion::mpl::concepts::ThreeWayComparable test case 1 failing");
static_assert(ThreeWayComparable<int, double>,
"hyperion::mpl::concepts::ThreeWayComparable test case 2 failing");
static_assert(!ThreeWayComparable<int, not_comparable>,
"hyperion::mpl::concepts::ThreeWayComparable test case 3 failing");
} // namespace _test
} // namespace hyperion::mpl::concepts

#endif // HYPERION_MPL_CONCEPTS_IS_COMPARABLE_H
80 changes: 80 additions & 0 deletions include/hyperion/mpl/concepts/operator_able.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/// @file operator_able.h
/// @author Braxton Salyer <[email protected]>
/// @brief Meta-programming C++20 concept definitions to determine if a type
/// (or types) support an operator
/// @version 0.1
/// @date 2024-01-27
///
/// MIT License
/// @copyright Copyright (c) 2024 Braxton Salyer <[email protected]>
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to
/// deal in the Software without restriction, including without limitation the
/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
/// sell copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
/// IN THE SOFTWARE.

#ifndef HYPERION_MPL_CONCEPTS_OPERATOR_ABLE_H
#define HYPERION_MPL_CONCEPTS_OPERATOR_ABLE_H

#include <hyperion/mpl/type_traits/is_operator_able.h>

namespace hyperion::mpl::concepts {

template<typename TLhs>
concept UnaryPlusable = type_traits::is_unary_plusable_v<TLhs>;

template<typename TLhs>
concept UnaryMinusable = type_traits::is_unary_minusable_v<TLhs>;

template<typename TLhs>
concept BinaryNotable = type_traits::is_binary_notable_v<TLhs>;

template<typename TLhs>
concept BooleanNotable = type_traits::is_boolean_notable_v<TLhs>;

template<typename TLhs>
concept Addressable = type_traits::is_addressable_v<TLhs>;

template<typename TLhs>
concept Arrowable = type_traits::is_arrowable_v<TLhs>;

template<typename TLhs, typename TRhs = TLhs>
concept Addable = type_traits::is_addable_v<TLhs, TRhs>;

template<typename TLhs, typename TRhs = TLhs>
concept Subtractable = type_traits::is_subtractable_v<TLhs, TRhs>;

template<typename TLhs, typename TRhs = TLhs>
concept Multipliable = type_traits::is_multipliable_v<TLhs, TRhs>;

template<typename TLhs, typename TRhs = TLhs>
concept Dividible = type_traits::is_dividible_v<TLhs, TRhs>;

template<typename TLhs, typename TRhs = TLhs>
concept BinaryAndable = type_traits::is_binary_andable_v<TLhs, TRhs>;

template<typename TLhs, typename TRhs = TLhs>
concept BinaryOrable = type_traits::is_binary_orable_v<TLhs, TRhs>;

template<typename TLhs, typename TRhs = TLhs>
concept BooleanAndable = type_traits::is_boolean_andable_v<TLhs, TRhs>;

template<typename TLhs, typename TRhs = TLhs>
concept BooleanOrable = type_traits::is_boolean_orable_v<TLhs, TRhs>;

} // namespace hyperion::mpl::concepts

#endif // HYPERION_MPL_CONCEPTS_OPERATOR_ABLE_H
41 changes: 41 additions & 0 deletions include/hyperion/mpl/concepts/std_supplemental.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/// @file std_supplemental.h
/// @author Braxton Salyer <[email protected]>
/// @brief Supplemental C++20 concept definitions to those provided in
/// `#include <concepts>` to provide functionality missing from the standard
/// @version 0.1
/// @date 2024-01-27
///
/// MIT License
/// @copyright Copyright (c) 2024 Braxton Salyer <[email protected]>
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in all
/// copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
/// SOFTWARE.

#ifndef HYPERION_MPL_CONCEPTS_STD_SUPPLEMENTAL_H
#define HYPERION_MPL_CONCEPTS_STD_SUPPLEMENTAL_H

#include <hyperion/mpl/type_traits/std_supplemental.h>

namespace hyperion::mpl::concepts {

template<typename TType>
concept TriviallyMovable = type_traits::is_trivially_movable_v<TType>;

} // namespace hyperion::mpl::concepts

#endif // HYPERION_MPL_CONCEPTS_STD_SUPPLEMENTAL_H
8 changes: 8 additions & 0 deletions include/hyperion/mpl/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
/// SOFTWARE.

#ifndef HYPERION_MPL_TYPE_TRAITS_H
#define HYPERION_MPL_TYPE_TRAITS_H

#include <hyperion/mpl/type_traits/is_comparable.h>
#include <hyperion/mpl/type_traits/is_operator_able.h>
#include <hyperion/mpl/type_traits/std_supplemental.h>

#endif // HYPERION_MPL_TYPE_TRAITS_H
Loading

0 comments on commit 36d1c72

Please sign in to comment.