-
Notifications
You must be signed in to change notification settings - Fork 241
Define C++20 concepts #848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mborland
wants to merge
19
commits into
boostorg:develop
Choose a base branch
from
mborland:concepts
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a72ab6c
Define C++20 concepts
mborland c495bf7
Add intel _Quad type
mborland a4cd40f
Add arbitrary arithmetic concepts
mborland b5344d5
Add test on special function (beta)
mborland 7252320
Add policy concept
mborland 046217c
Iterator concept example in statistics
mborland e9af348
Tighten definitions of built-in concepts by excluding 128 bit extensions
mborland 9a0905a
Add definition for container
mborland b56de86
Workaround for libcpp++ partial implementation of concepts
mborland b802b7c
Add complex number support
mborland b03cbf5
Add execution policy concept
mborland 6bd07ec
Add any numerical type (int, floating, complex) concept
mborland 5b81a37
Remove libc++ workaround
mborland 3420530
Define our own derived_from as std not available on all platforms
mborland 7a0ea9b
Merge branch 'concepts' of https://github.com/mborland/math into conc…
jzmaddock 7fa561d
Update log1p for concept tests.
jzmaddock 1fb3a58
Merge remote-tracking branch 'upstream/develop' into concepts
mborland 054214c
Merge remote-tracking branch 'upstream/concepts' into concepts
mborland 2f889d4
Change concept to allow integer promotion to double a la STL
mborland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// (C) Copyright Matt Borland 2022. | ||
// Use, modification and distribution are subject to the | ||
// Boost Software License, Version 1.0. (See accompanying file | ||
// LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#ifndef BOOST_MATH_CONCEPTS_CONCEPTS_HPP | ||
#define BOOST_MATH_CONCEPTS_CONCEPTS_HPP | ||
|
||
#if __cplusplus >= 202002L || _MSVC_LANG >= 202002L | ||
#if __has_include(<concepts>) | ||
#include <concepts> | ||
|
||
#include <type_traits> | ||
#include <boost/math/tools/config.hpp> | ||
|
||
namespace boost::math::concepts { | ||
|
||
template <typename T> | ||
concept Integral = std::is_integral_v<T> | ||
#ifdef __SIZEOF_INT128__ | ||
|| std::is_same_v<__int128_t, T> | ||
|| std::is_same_v<__uint128_t, T> | ||
#endif | ||
; | ||
|
||
|
||
template <typename T> | ||
concept Signed_integral = std::is_integral_v<T> && std::is_signed_v<T> | ||
#ifdef __SIZEOF_INT128__ | ||
|| std::is_same_v<__int128_t, T> | ||
#endif | ||
; | ||
|
||
template <typename T> | ||
concept Unsigned_integral = std::is_integral_v<T> && std::is_unsigned_v<T> | ||
#ifdef __SIZEOF_INT128__ | ||
|| std::is_same_v<__uint128_t, T> | ||
#endif | ||
; | ||
|
||
template <typename T> | ||
concept Real = std::is_floating_point_v<T> | ||
#ifdef BOOST_HAS_FLOAT128 | ||
|| std::is_same_v<__float128, T> | ||
mborland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#endif | ||
; | ||
|
||
template <typename T> | ||
concept Arithmetic = Integral<T> || Real<T>; | ||
|
||
template <typename T> | ||
concept Signed_arithmetic = Arithmetic<T> && (std::is_signed_v<T> | ||
#ifdef __SIZEOF_INT128__ | ||
|| std::is_same_v<__int128_t, T> | ||
#endif | ||
); | ||
|
||
template <typename T> | ||
concept Unsigned_arithmetic = Arithmetic<T> && (std::is_unsigned_v<T> | ||
#ifdef __SIZEOF_INT128__ | ||
|| std::is_same_v<__uint128_t, T> | ||
#endif | ||
); | ||
|
||
} | ||
|
||
#define BOOST_MATH_INTEGRAL boost::math::concepts::Integral<T> | ||
#define BOOST_MATH_SIGNED_INTEGRAL boost::math::concepts::Signed_integral<T> | ||
#define BOOST_MATH_UNSIGNED_INTEGRAL boost::math::concepts::Unsigned_integral<T> | ||
#define BOOST_MATH_REAL boost::math::concepts::Real | ||
#define BOOST_MATH_ARITHMETIC boost::math::concepts::Arithmetic | ||
#define BOOST_MATH_SIGNED_ARITHMETIC boost::math::concepts::Signed_arithmetic | ||
#define BOOST_MATH_UNSIGNED_ARITHMETIC boost::math::concepts::Unsigned_arithmetic | ||
#define BOOST_MATH_REQUIRES(X, T) requires X<T> | ||
|
||
#endif | ||
#endif | ||
|
||
#ifndef BOOST_MATH_INTEGRAL | ||
# define BOOST_MATH_INTEGRAL typename | ||
#endif | ||
|
||
#ifndef BOOST_MATH_SIGNED_INTEGRAL | ||
# define BOOST_MATH_SIGNED_INTEGRAL typename | ||
#endif | ||
|
||
#ifndef BOOST_MATH_UNSIGNED_INTEGRAL | ||
# define BOOST_MATH_UNSIGNED_INTEGRAL typename | ||
#endif | ||
|
||
#ifndef BOOST_MATH_REAL | ||
# define BOOST_MATH_REAL typename | ||
#endif | ||
|
||
#ifndef BOOST_MATH_ARITHMETIC | ||
# define BOOST_MATH_ARITHMETIC typename | ||
#endif | ||
|
||
#ifndef BOOST_MATH_SIGNED_ARITHMETIC | ||
# define BOOST_MATH_SIGNED_ARITHMETIC typename | ||
#endif | ||
|
||
#ifndef BOOST_MATH_UNSIGNED_ARITHMETIC | ||
# define BOOST_MATH_UNSIGNED_ARITHMETIC typename | ||
#endif | ||
|
||
#ifndef BOOST_MATH_REQUIRES | ||
# define BOOST_MATH_REQUIRES(X, T) | ||
#endif | ||
|
||
#endif // BOOST_MATH_CONCEPTS_CONCEPTS_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.