-
Notifications
You must be signed in to change notification settings - Fork 68
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
Numeric ranges #312
Open
cjdb
wants to merge
9
commits into
CaseyCarter:master
Choose a base branch
from
cjdb:numeric-ranges
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
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
Numeric ranges #312
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1ace59c
establishes the basis for numeric ranges
cjdb 9d54dfd
adds algebraic concepts, identity numeric trait, and accumulate overl…
cjdb b0498f0
adds `negate` function object, fixes minus requirements, adjusts whit…
cjdb e0fe9af
adds ranges::ext::partial_sum
cjdb f6a4292
removes right_identity<modulus>
cjdb fb829d1
changes copyright and licencing
cjdb 2b5331f
adds ranges::adjacent_difference
cjdb fba4255
updates to spacing
cjdb 6e7c3a3
adds a test for numeric concepts and applies patches
cjdb File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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,53 @@ | ||
// cmcstl2 - A concept-enabled C++ standard library | ||
// | ||
// Copyright Casey Carter | ||
// Copyright Christopher Di Bella | ||
// | ||
// Use, modification and distribution is subject to the | ||
// Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
// Project home: https://github.com/caseycarter/cmcstl2 | ||
// | ||
#ifndef STL2_DETAIL_CONCEPTS_NUMERIC_HPP | ||
#define STL2_DETAIL_CONCEPTS_NUMERIC_HPP | ||
|
||
#include <stl2/detail/concepts/numeric/magma.hpp> | ||
#include <stl2/detail/concepts/numeric/semigroup.hpp> | ||
#include <stl2/detail/concepts/numeric/monoid.hpp> | ||
#include <stl2/detail/concepts/callable.hpp> | ||
#include <stl2/detail/fwd.hpp> | ||
|
||
STL2_OPEN_NAMESPACE { | ||
namespace ext { | ||
template<class BOp, class I1, class I2, class O> | ||
META_CONCEPT IndirectMagma = | ||
Readable<I1> && | ||
Readable<I2> && | ||
Writable<O, indirect_result_t<BOp&, I1, I2>> && | ||
Magma<BOp&, iter_value_t<I1>&, iter_value_t<I2>&> && | ||
Magma<BOp&, iter_value_t<I1>&, iter_reference_t<I2>&> && | ||
Magma<BOp&, iter_reference_t<I1>, iter_value_t<I2>&> && | ||
Magma<BOp&, iter_reference_t<I1>, iter_reference_t<I2>> && | ||
Magma<BOp&, iter_common_reference_t<I1>, iter_common_reference_t<I2>>; | ||
|
||
template<class BOp, class I1, class I2, class O> | ||
META_CONCEPT IndirectSemigroup = IndirectMagma<BOp, I1, I2, O> && | ||
Semigroup<BOp&, iter_value_t<I1>&, iter_value_t<I2>&> && | ||
Semigroup<BOp&, iter_value_t<I1>&, iter_reference_t<I2>&> && | ||
Semigroup<BOp&, iter_reference_t<I1>, iter_value_t<I2>&> && | ||
Semigroup<BOp&, iter_reference_t<I1>, iter_reference_t<I2>> && | ||
Semigroup<BOp&, iter_common_reference_t<I1>, iter_common_reference_t<I2>>; | ||
|
||
template<class BOp, class I1, class I2, class O> | ||
META_CONCEPT IndirectMonoid = IndirectSemigroup<BOp, I1, I2, O> && | ||
Monoid<BOp&, iter_value_t<I1>&, iter_value_t<I2>&> && | ||
Monoid<BOp&, iter_value_t<I1>&, iter_reference_t<I2>&> && | ||
Monoid<BOp&, iter_reference_t<I1>, iter_value_t<I2>&> && | ||
Monoid<BOp&, iter_reference_t<I1>, iter_reference_t<I2>> && | ||
Monoid<BOp&, iter_common_reference_t<I1>, iter_common_reference_t<I2>>; | ||
} // namespace ext | ||
} STL2_CLOSE_NAMESPACE | ||
|
||
#endif // STL2_DETAIL_CONCEPTS_NUMERIC_HPP |
This file contains 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,39 @@ | ||
// cmcstl2 - A concept-enabled C++ standard library | ||
// | ||
// Copyright Casey Carter | ||
// Copyright Christopher Di Bella | ||
// | ||
// Use, modification and distribution is subject to the | ||
// Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
// Project home: https://github.com/caseycarter/cmcstl2 | ||
// | ||
#ifndef STL2_DETAIL_CONCEPTS_NUMERIC_MAGMA_HPP | ||
#define STL2_DETAIL_CONCEPTS_NUMERIC_MAGMA_HPP | ||
|
||
#include <stl2/detail/concepts/core.hpp> | ||
#include <stl2/detail/concepts/function.hpp> | ||
#include <stl2/detail/fwd.hpp> | ||
|
||
STL2_OPEN_NAMESPACE { | ||
namespace ext { | ||
template<class BOp, class T, class U> | ||
META_CONCEPT Magma = | ||
Common<T, U> && | ||
RegularInvocable<BOp, T, T> && | ||
RegularInvocable<BOp, U, U> && | ||
RegularInvocable<BOp, T, U> && | ||
RegularInvocable<BOp, U, T> && | ||
Common<invoke_result_t<BOp&, T, U>, T> && | ||
Common<invoke_result_t<BOp&, T, U>, U> && | ||
Same<invoke_result_t<BOp&, T, U>, invoke_result_t<BOp&, U, T>>; | ||
// axiom: Let `bop` be an object of type `BOp`, `t` be an object of type `T`, and `u` be an | ||
// object of type `U`. The expression `invoke(bop, t, u)` must return a result that is | ||
// representable by `common_type_t<T, U>`. | ||
// axiom: The result of `invoke(bop, t, u)` needn't be the same as `invoke(bop, u, t)`. | ||
} // namespace ext | ||
} STL2_CLOSE_NAMESPACE | ||
|
||
#endif // STL2_DETAIL_CONCEPTS_NUMERIC_MAGMA_HPP |
This file contains 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,29 @@ | ||
// cmcstl2 - A concept-enabled C++ standard library | ||
// | ||
// Copyright Casey Carter | ||
// Copyright Christopher Di Bella | ||
// | ||
// Use, modification and distribution is subject to the | ||
// Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
// Project home: https://github.com/caseycarter/cmcstl2 | ||
// | ||
#ifndef STL2_DETAIL_CONCEPTS_NUMERIC_MONOID_HPP | ||
#define STL2_DETAIL_CONCEPTS_NUMERIC_MONOID_HPP | ||
|
||
#include <stl2/detail/concepts/numeric/semigroup.hpp> | ||
#include <stl2/detail/fwd.hpp> | ||
#include <stl2/detail/numeric_traits/identity.hpp> | ||
|
||
STL2_OPEN_NAMESPACE { | ||
namespace ext { | ||
template<class BOp, class T, class U> | ||
META_CONCEPT Monoid = Semigroup<BOp, T, U> && requires { | ||
typename two_sided_identity_t<BOp, __uncvref<T>, __uncvref<U>>; | ||
}; | ||
} // namespace ext | ||
} STL2_CLOSE_NAMESPACE | ||
|
||
#endif // STL2_DETAIL_CONCEPTS_NUMERIC_MONOID_HPP |
This file contains 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,29 @@ | ||
// cmcstl2 - A concept-enabled C++ standard library | ||
// | ||
// Copyright Casey Carter | ||
// Copyright Christopher Di Bella | ||
// | ||
// Use, modification and distribution is subject to the | ||
// Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
// Project home: https://github.com/caseycarter/cmcstl2 | ||
// | ||
#ifndef STL2_DETAIL_CONCEPTS_NUMERIC_SEMIGROUP_HPP | ||
#define STL2_DETAIL_CONCEPTS_NUMERIC_SEMIGROUP_HPP | ||
|
||
#include <stl2/detail/concepts/numeric/magma.hpp> | ||
#include <stl2/detail/fwd.hpp> | ||
|
||
STL2_OPEN_NAMESPACE { | ||
namespace ext { | ||
template<class BOp, class T, class U> | ||
META_CONCEPT Semigroup = Magma<BOp, T, U>; | ||
// axiom: Let `bop` be an object of type `BOp`, `t` be an object of type `T`, and `u` be an | ||
// object of type `U`. The expression `invoke(bop, t, invoke(bop, t, u))` is | ||
// expression-equivalent to `invoke(bop, invoke(bop, t, u), u)`. | ||
} // namespace ext | ||
} STL2_CLOSE_NAMESPACE | ||
|
||
#endif // STL2_DETAIL_CONCEPTS_NUMERIC_SEMIGROUP_HPP |
This file contains 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,23 @@ | ||
// cmcstl2 - A concept-enabled C++ standard library | ||
// | ||
// Copyright Casey Carter | ||
// Copyright Christopher Di Bella | ||
// | ||
// Use, modification and distribution is subject to the | ||
// Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
// Project home: https://github.com/caseycarter/cmcstl2 | ||
// | ||
#ifndef STL2_DETAIL_FUNCTIONAL_ARITHMETIC_HPP | ||
#define STL2_DETAIL_FUNCTIONAL_ARITHMETIC_HPP | ||
|
||
#include <stl2/detail/functional/arithmetic/plus.hpp> | ||
#include <stl2/detail/functional/arithmetic/minus.hpp> | ||
#include <stl2/detail/functional/arithmetic/negate.hpp> | ||
#include <stl2/detail/functional/arithmetic/product.hpp> | ||
#include <stl2/detail/functional/arithmetic/quotient.hpp> | ||
#include <stl2/detail/functional/arithmetic/modulus.hpp> | ||
|
||
#endif // STL2_DETAIL_FUNCTIONAL_ARITHMETIC_HPP |
This file contains 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,64 @@ | ||
// cmcstl2 - A concept-enabled C++ standard library | ||
// | ||
// Copyright Casey Carter | ||
// Copyright Christopher Di Bella | ||
// | ||
// Use, modification and distribution is subject to the | ||
// Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
// Project home: https://github.com/caseycarter/cmcstl2 | ||
// | ||
#ifndef STL2_DETAIL_FUNCTIONAL_ARITHMETIC_MINUS_HPP | ||
#define STL2_DETAIL_FUNCTIONAL_ARITHMETIC_MINUS_HPP | ||
|
||
#include <stl2/detail/concepts/core.hpp> | ||
#include <stl2/detail/functional/arithmetic/plus.hpp> | ||
#include <stl2/detail/functional/arithmetic/negate.hpp> | ||
#include <stl2/detail/fwd.hpp> | ||
#include <stl2/detail/numeric_traits/identity.hpp> | ||
#include <type_traits> | ||
#include <utility> | ||
|
||
STL2_OPEN_NAMESPACE { | ||
namespace ext { | ||
template<class T, class U> | ||
META_CONCEPT __differenceable_with = | ||
__summable_with<T, U> && | ||
__negatable<T> && | ||
__negatable<U> && | ||
requires(__uncvref<T> t, __uncvref<U> u) { | ||
{ t -= std::forward<U>(u) } -> CommonReference<T&>; | ||
{ u -= std::forward<T>(t) } -> CommonReference<U&>; | ||
{ std::forward<T>(t) - std::forward<T>(t) } -> Common<T>; | ||
{ std::forward<U>(u) - std::forward<U>(u) } -> Common<U>; | ||
{ std::forward<T>(t) - std::forward<U>(u) } -> Common<T>; | ||
{ std::forward<T>(t) - std::forward<U>(u) } -> Common<U>; | ||
requires Same<decltype(std::forward<T>(t) - std::forward<U>(u)), | ||
decltype(std::forward<U>(t) - std::forward<T>(u))>; | ||
}; | ||
// axiom: `t - t` is equivalent to `T{}` | ||
// axiom: `t - (-t)` is equivalent to `t + t` | ||
// axiom: `-t - t` is equivalent to `-(t + t)` | ||
// axiom: `t + t - t` is equivalent to `t` | ||
|
||
struct minus { | ||
template<class T, __differenceable_with<T> U> | ||
constexpr decltype(auto) operator()(T&& t, U&& u) const { | ||
return std::forward<T>(t) - std::forward<U>(u); | ||
} | ||
|
||
using is_transparent = std::true_type; | ||
}; | ||
|
||
template<class T, class U> | ||
requires Magma<__stl2::ext::minus, T, U> | ||
struct right_identity<__stl2::ext::minus, T, U> | ||
: private right_identity<__stl2::ext::plus, T, U> { | ||
using right_identity<__stl2::ext::plus, T, U>::value; | ||
}; | ||
} // namespace ext | ||
} STL2_CLOSE_NAMESPACE | ||
|
||
#endif // STL2_DETAIL_FUNCTIONAL_ARITHMETIC_MINUS_HPP |
This file contains 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,50 @@ | ||
// cmcstl2 - A concept-enabled C++ standard library | ||
// | ||
// Copyright Casey Carter | ||
// Copyright Christopher Di Bella | ||
// | ||
// Use, modification and distribution is subject to the | ||
// Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
// Project home: https://github.com/caseycarter/cmcstl2 | ||
// | ||
#ifndef STL2_DETAIL_FUNCTIONAL_ARITHMETIC_MODULUS_HPP | ||
#define STL2_DETAIL_FUNCTIONAL_ARITHMETIC_MODULUS_HPP | ||
|
||
#include <stl2/detail/concepts/core.hpp> | ||
#include <stl2/detail/functional/arithmetic/plus.hpp> | ||
#include <stl2/detail/functional/arithmetic/quotient.hpp> | ||
#include <stl2/detail/fwd.hpp> | ||
#include <stl2/detail/numeric_traits/identity.hpp> | ||
#include <type_traits> | ||
#include <utility> | ||
|
||
STL2_OPEN_NAMESPACE { | ||
namespace ext { | ||
template<class T, class U> | ||
META_CONCEPT __modulo_with = __summable_with<T, U> && __divisible_with<T, U> && | ||
requires(__uncvref<T> t, __uncvref<U> u) { | ||
{ t %= std::forward<U>(u) } -> CommonReference<T&>; | ||
{ u %= std::forward<T>(t) } -> CommonReference<U&>; | ||
{ std::forward<T>(t) % std::forward<T>(t) } -> Common<T>; | ||
{ std::forward<U>(u) % std::forward<U>(u) } -> Common<U>; | ||
{ std::forward<T>(t) % std::forward<U>(u) } -> Common<T>; | ||
{ std::forward<T>(t) % std::forward<U>(u) } -> Common<U>; | ||
requires Same<decltype(std::forward<T>(t) / std::forward<U>(u)), | ||
decltype(std::forward<U>(t) / std::forward<T>(u))>; | ||
}; | ||
// Let n, q, r, t all be distinct objects of type T. | ||
// axiom: `t % q == q * r + n` | ||
|
||
struct modulus { | ||
template<class T, __modulo_with<T> U> | ||
constexpr decltype(auto) operator()(T&& t, U&& u) const { | ||
return std::forward<T>(t) % std::forward<U>(u); | ||
} | ||
}; | ||
} // namespace ext | ||
} STL2_CLOSE_NAMESPACE | ||
|
||
#endif // STL2_DETAIL_FUNCTIONAL_ARITHMETIC_MODULUS_HPP |
This file contains 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,39 @@ | ||
// cmcstl2 - A concept-enabled C++ standard library | ||
// | ||
// Copyright Casey Carter | ||
// Copyright Christopher Di Bella | ||
// | ||
// Use, modification and distribution is subject to the | ||
// Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
// Project home: https://github.com/caseycarter/cmcstl2 | ||
// | ||
#ifndef STL2_DETAIL_FUNCTIONAL_ARITHMETIC_NEGATE_HPP | ||
#define STL2_DETAIL_FUNCTIONAL_ARITHMETIC_NEGATE_HPP | ||
|
||
#include <stl2/detail/concepts/core.hpp> | ||
#include <stl2/detail/functional/arithmetic/plus.hpp> | ||
#include <stl2/detail/fwd.hpp> | ||
#include <stl2/detail/numeric_traits/identity.hpp> | ||
#include <type_traits> | ||
#include <utility> | ||
|
||
STL2_OPEN_NAMESPACE { | ||
template<class T> | ||
META_CONCEPT __negatable = requires(T&& t) { | ||
{ -std::forward<T>(t) } -> Common<T>; | ||
}; | ||
|
||
struct negate { | ||
template<__negatable T> | ||
constexpr decltype(auto) operator()(T&& t) const { | ||
return -std::forward<T>(t); | ||
} | ||
|
||
using is_transparent = std::true_type; | ||
}; | ||
} STL2_CLOSE_NAMESPACE | ||
|
||
#endif // STL2_DETAIL_FUNCTIONAL_ARITHMETIC_NEGATE_HPP |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like that
T
andU
have had their cv- and ref-qualifiers removed, but I can't think of a better way to implement this at the moment.