Skip to content
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

Changed result_of to invoke_result for C++20 compatibility. #261

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/rapidcheck/Gen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace gen {

// Forward declare this so we don't need to include Transform.h
template <typename T, typename Mapper>
Gen<Decay<typename std::result_of<Mapper(T)>::type>> map(Gen<T> gen,
Gen<Decay<typename std::invoke_result<Mapper,T>::type>> map(Gen<T> gen,
Mapper &&mapper);

} // namespace gen
Expand Down
2 changes: 1 addition & 1 deletion include/rapidcheck/Seq.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Seq {
/// Creates a new `Seq` using the implementation class specificed by the
/// type parameter constructed by forwarding the given arguments.
template <typename Impl, typename... Args>
friend Seq<typename std::result_of<Impl()>::type::ValueType>
friend Seq<typename std::invoke_result<Impl>::type::ValueType>
makeSeq(Args &&... args);

public:
Expand Down
4 changes: 2 additions & 2 deletions include/rapidcheck/Seq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ Seq<T> &Seq<T>::operator=(const Seq &rhs) {
}

template <typename Impl, typename... Args>
Seq<typename std::result_of<Impl(void)>::type::ValueType> makeSeq(Args &&... args) {
using SeqT = Seq<typename std::result_of<Impl(void)>::type::ValueType>;
Seq<typename std::invoke_result<Impl>::type::ValueType> makeSeq(Args &&... args) {
using SeqT = Seq<typename std::invoke_result<Impl>::type::ValueType>;
using ImplT = typename SeqT::template SeqImpl<Impl>;

SeqT seq;
Expand Down
6 changes: 3 additions & 3 deletions include/rapidcheck/detail/ApplyTuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct ApplyTupleImpl;

template <typename... Ts, std::size_t... Indexes, typename Callable>
struct ApplyTupleImpl<std::tuple<Ts...>, Callable, IndexSequence<Indexes...>> {
using ReturnType = typename std::result_of<Callable(Ts &&...)>::type;
using ReturnType = typename std::invoke_result<Callable,Ts &&...>::type;

static ReturnType apply(std::tuple<Ts...> &&tuple, Callable &&callable) {
return callable(std::move(std::get<Indexes>(tuple))...);
Expand All @@ -24,7 +24,7 @@ template <typename... Ts, std::size_t... Indexes, typename Callable>
struct ApplyTupleImpl<std::tuple<Ts...> &,
Callable,
IndexSequence<Indexes...>> {
using ReturnType = typename std::result_of<Callable(Ts &...)>::type;
using ReturnType = typename std::invoke_result<Callable,Ts &...>::type;

static ReturnType apply(std::tuple<Ts...> &tuple, Callable &&callable) {
return callable(std::get<Indexes>(tuple)...);
Expand All @@ -35,7 +35,7 @@ template <typename... Ts, std::size_t... Indexes, typename Callable>
struct ApplyTupleImpl<const std::tuple<Ts...> &,
Callable,
IndexSequence<Indexes...>> {
using ReturnType = typename std::result_of<Callable(const Ts &...)>::type;
using ReturnType = typename std::invoke_result<Callable,const Ts &...>::type;

static ReturnType apply(const std::tuple<Ts...> &tuple, Callable &&callable) {
return callable(std::get<Indexes>(tuple)...);
Expand Down
4 changes: 2 additions & 2 deletions include/rapidcheck/gen/Container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class UniqueContainerStrategy {
int size,
std::size_t count,
const Gen<T> &gen) const {
using Key = Decay<typename std::result_of<F(T)>::type>;
using Key = Decay<typename std::invoke_result<F,T>::type>;
std::set<Key> values;
return detail::generateShrinkables(random,
size,
Expand All @@ -259,7 +259,7 @@ class UniqueContainerStrategy {
template <typename T>
Seq<Shrinkables<T>>
shrinkElements(const Shrinkables<T> &shrinkables) const {
using Key = Decay<typename std::result_of<F(T)>::type>;
using Key = Decay<typename std::invoke_result<F,T>::type>;
const auto keys = std::make_shared<std::set<Key>>();
for (const auto &shrinkable : shrinkables) {
keys->insert(m_f(shrinkable.value()));
Expand Down
2 changes: 1 addition & 1 deletion include/rapidcheck/gen/Create.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gen<Decay<T>> just(T &&value);
/// called lazily on actual generation. This is useful when implementing
/// recursive generators where a generator must reference itself.
template <typename Callable>
Gen<typename std::result_of<Callable()>::type::ValueType>
Gen<typename std::invoke_result<Callable>::type::ValueType>
lazy(Callable &&callable);

} // namespace gen
Expand Down
2 changes: 1 addition & 1 deletion include/rapidcheck/gen/Create.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gen<Decay<T>> just(T &&value) {
}

template <typename Callable>
Gen<typename std::result_of<Callable()>::type::ValueType>
Gen<typename std::invoke_result<Callable>::type::ValueType>
lazy(Callable &&callable) {
return
[=](const Random &random, int size) { return callable()(random, size); };
Expand Down
10 changes: 5 additions & 5 deletions include/rapidcheck/gen/Transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ namespace gen {
/// Returns a generator based on the given generator but mapped with the given
/// mapping function.
template <typename T, typename Mapper>
Gen<Decay<typename std::result_of<Mapper(T)>::type>> map(Gen<T> gen,
Gen<Decay<typename std::invoke_result<Mapper,T>::type>> map(Gen<T> gen,
Mapper &&mapper);

/// Convenience function which calls `map(Gen<T>, Mapper)` with
/// `gen::arbitrary<T>`
template <typename T, typename Mapper>
Gen<Decay<typename std::result_of<Mapper(T)>::type>> map(Mapper &&mapper);
Gen<Decay<typename std::invoke_result<Mapper,T>::type>> map(Mapper &&mapper);

/// Monadic bind. Takes a `Gen<T>` and a function from a `T` to a `Gen<U>` and
/// returns a `Gen<U>`. When shrinking, the value generated by the first
/// generator will be shrunk first, then the second.
template <typename T, typename Mapper>
Gen<typename std::result_of<Mapper(T)>::type::ValueType>
Gen<typename std::invoke_result<Mapper,T>::type::ValueType>
mapcat(Gen<T> gen, Mapper &&mapper);

/// Flattens a generator of generators of `T` into a generator of `T`. This is
Expand All @@ -31,7 +31,7 @@ Gen<T> join(Gen<Gen<T>> gen);
/// Calls the given callable with values generated by the given generators. Has
/// tuple semantics when shrinking.
template <typename Callable, typename... Ts>
Gen<typename std::result_of<Callable(Ts...)>::type>
Gen<typename std::invoke_result<Callable,Ts...>::type>
apply(Callable &&callable, Gen<Ts>... gens);

/// Returns a generator that casts the generated values to `T` using
Expand All @@ -52,7 +52,7 @@ Gen<T> scale(double scale, Gen<T> gen);
/// Creates a generator by taking a callable which gets passed the current size
/// and is expected to return a generator.
template <typename Callable>
Gen<typename std::result_of<Callable(int)>::type::ValueType>
Gen<typename std::invoke_result<Callable,int>::type::ValueType>
withSize(Callable &&callable);

/// Use this to disable shrinking for a given generator. When a failing case is
Expand Down
14 changes: 7 additions & 7 deletions include/rapidcheck/gen/Transform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace detail {
template <typename T, typename Mapper>
class MapGen {
public:
using U = Decay<typename std::result_of<Mapper(T)>::type>;
using U = Decay<typename std::invoke_result<Mapper,T>::type>;

template <typename MapperArg>
MapGen(Gen<T> gen, MapperArg &&mapper)
Expand All @@ -32,7 +32,7 @@ class MapGen {
template <typename T, typename Mapper>
class MapcatGen {
public:
using U = typename std::result_of<Mapper(T)>::type::ValueType;
using U = typename std::invoke_result<Mapper,T>::type::ValueType;

template <typename MapperArg>
explicit MapcatGen(Gen<T> gen, MapperArg &&mapper)
Expand Down Expand Up @@ -73,19 +73,19 @@ class JoinGen {
} // namespace detail

template <typename T, typename Mapper>
Gen<Decay<typename std::result_of<Mapper(T)>::type>> map(Gen<T> gen,
Gen<Decay<typename std::invoke_result<Mapper,T>::type>> map(Gen<T> gen,
Mapper &&mapper) {
return detail::MapGen<T, Decay<Mapper>>(std::move(gen),
std::forward<Mapper>(mapper));
}

template <typename T, typename Mapper>
Gen<Decay<typename std::result_of<Mapper(T)>::type>> map(Mapper &&mapper) {
Gen<Decay<typename std::invoke_result<Mapper,T>::type>> map(Mapper &&mapper) {
return gen::map(gen::arbitrary<T>(), std::forward<Mapper>(mapper));
}

template <typename T, typename Mapper>
Gen<typename std::result_of<Mapper(T)>::type::ValueType>
Gen<typename std::invoke_result<Mapper,T>::type::ValueType>
mapcat(Gen<T> gen, Mapper &&mapper) {
return detail::MapcatGen<T, Decay<Mapper>>(std::move(gen),
std::forward<Mapper>(mapper));
Expand All @@ -97,7 +97,7 @@ Gen<T> join(Gen<Gen<T>> gen) {
}

template <typename Callable, typename... Ts>
Gen<typename std::result_of<Callable(Ts...)>::type> apply(Callable &&callable,
Gen<typename std::invoke_result<Callable,Ts...>::type> apply(Callable &&callable,
Gen<Ts>... gens) {
return gen::map(gen::tuple(std::move(gens)...),
[=](std::tuple<Ts...> &&tuple) {
Expand All @@ -124,7 +124,7 @@ Gen<T> scale(double scale, Gen<T> gen) {
}

template <typename Callable>
Gen<typename std::result_of<Callable(int)>::type::ValueType>
Gen<typename std::invoke_result<Callable,int>::type::ValueType>
withSize(Callable &&callable) {
return [=](const Random &random, int size) {
return callable(size)(random, size);
Expand Down
8 changes: 4 additions & 4 deletions include/rapidcheck/seq/Transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Seq<T> takeWhile(Seq<T> seq, Predicate &&pred);

/// Maps the elements of the given `Seq` using the given callable.
template <typename T, typename Mapper>
Seq<Decay<typename std::result_of<Mapper(T)>::type>> map(Seq<T> seq,
Seq<Decay<typename std::invoke_result<Mapper,T>::type>> map(Seq<T> seq,
Mapper &&mapper);

/// Takes elements from the given `Seq`s and passes them as arguments to the
Expand All @@ -33,7 +33,7 @@ Seq<Decay<typename std::result_of<Mapper(T)>::type>> map(Seq<T> seq,
/// Fun fact: Also works with no sequences and in that case returns an infinite
/// sequence of the return values of calling the given callable.
template <typename... Ts, typename Zipper>
Seq<Decay<typename std::result_of<Zipper(Ts...)>::type>>
Seq<Decay<typename std::invoke_result<Zipper,Ts...>::type>>
zipWith(Zipper &&zipper, Seq<Ts>... seqs);

/// Skips elements not matching the given predicate from the given stream.
Expand All @@ -51,14 +51,14 @@ Seq<T> concat(Seq<T> seq, Seq<Ts>... seqs);
/// Maps each tuple elements of the given to `Seq`s to further `Seq`s and
/// concatenates them into one `Seq`. Sometimes called a "flat map".
template <typename T, typename Mapper>
Seq<typename std::result_of<Mapper(T)>::type::ValueType>
Seq<typename std::invoke_result<Mapper,T>::type::ValueType>
mapcat(Seq<T> seq, Mapper &&mapper);

/// Like `map` but expects the mapping functor to return a `Maybe`. If `Nothing`
/// is returned, the element is skipped. Otherwise, the `Maybe` is unwrapped and
/// included in the resulting `Seq`.
template <typename T, typename Mapper>
Seq<typename std::result_of<Mapper(T)>::type::ValueType>
Seq<typename std::invoke_result<Mapper,T>::type::ValueType>
mapMaybe(Seq<T> seq, Mapper &&mapper);

/// Creates a `Seq` which infinitely repeats the given `Seq`.
Expand Down
16 changes: 8 additions & 8 deletions include/rapidcheck/seq/Transform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class TakeWhileSeq {
template <typename Mapper, typename T>
class MapSeq {
public:
using U = Decay<typename std::result_of<Mapper(T)>::type>;
using U = Decay<typename std::invoke_result<Mapper,T>::type>;

template <typename MapperArg>
MapSeq(Seq<T> seq, MapperArg &&mapper)
Expand All @@ -142,7 +142,7 @@ class MapSeq {
template <typename Zipper, typename... Ts>
class ZipWithSeq {
public:
using U = Decay<typename std::result_of<Zipper(Ts...)>::type>;
using U = Decay<typename std::invoke_result<Zipper,Ts...>::type>;

template <typename ZipperArg>
ZipWithSeq(ZipperArg &&zipper, Seq<Ts>... seqs)
Expand Down Expand Up @@ -263,7 +263,7 @@ class ConcatSeq {
template <typename Mapper, typename T>
class MapcatSeq {
public:
using U = typename std::result_of<Mapper(T)>::type::ValueType;
using U = typename std::invoke_result<Mapper,T>::type::ValueType;

template <typename MapperArg>
MapcatSeq(Seq<T> seq, MapperArg &&mapper)
Expand Down Expand Up @@ -325,14 +325,14 @@ Seq<T> takeWhile(Seq<T> seq, Predicate &&pred) {
}

template <typename T, typename Mapper>
Seq<Decay<typename std::result_of<Mapper(T)>::type>> map(Seq<T> seq,
Seq<Decay<typename std::invoke_result<Mapper,T>::type>> map(Seq<T> seq,
Mapper &&mapper) {
return makeSeq<detail::MapSeq<Decay<Mapper>, T>>(
std::move(seq), std::forward<Mapper>(mapper));
}

template <typename... Ts, typename Zipper>
Seq<Decay<typename std::result_of<Zipper(Ts...)>::type>>
Seq<Decay<typename std::invoke_result<Zipper,Ts...>::type>>
zipWith(Zipper &&zipper, Seq<Ts>... seqs) {
return makeSeq<detail::ZipWithSeq<Decay<Zipper>, Ts...>>(
std::forward<Zipper>(zipper), std::move(seqs)...);
Expand All @@ -356,16 +356,16 @@ Seq<T> concat(Seq<T> seq, Seq<Ts>... seqs) {
}

template <typename T, typename Mapper>
Seq<typename std::result_of<Mapper(T)>::type::ValueType>
Seq<typename std::invoke_result<Mapper,T>::type::ValueType>
mapcat(Seq<T> seq, Mapper &&mapper) {
return makeSeq<detail::MapcatSeq<Decay<Mapper>, T>>(
std::move(seq), std::forward<Mapper>(mapper));
}

template <typename T, typename Mapper>
Seq<typename std::result_of<Mapper(T)>::type::ValueType>
Seq<typename std::invoke_result<Mapper,T>::type::ValueType>
mapMaybe(Seq<T> seq, Mapper &&mapper) {
using U = typename std::result_of<Mapper(T)>::type::ValueType;
using U = typename std::invoke_result<Mapper,T>::type::ValueType;
return seq::map(
seq::filter(seq::map(std::move(seq), std::forward<Mapper>(mapper)),
[](const Maybe<U> &x) { return !!x; }),
Expand Down
4 changes: 2 additions & 2 deletions include/rapidcheck/shrink/Shrink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class RemoveChunksSeq {
template <typename Container, typename Shrink>
class EachElementSeq {
public:
using T = typename std::result_of<Shrink(
typename Container::value_type)>::type::ValueType;
using T = typename std::invoke_result<Shrink,
typename Container::value_type>::type::ValueType;

template <typename ContainerArg, typename ShrinkArg>
explicit EachElementSeq(ContainerArg &&elements, ShrinkArg &&shrink)
Expand Down
6 changes: 3 additions & 3 deletions include/rapidcheck/shrinkable/Create.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ namespace shrinkable {
/// Creates a `Shrinkable` from a callable which returns the value and a
/// callable which returns the shrinks.
template <typename Value, typename Shrink>
Shrinkable<typename std::result_of<Value()>::type> lambda(Value &&value,
Shrinkable<typename std::invoke_result<Value>::type> lambda(Value &&value,
Shrink &&shrinks);

/// Creates a `Shrinkable` with no shrinks from a callable which returns the
/// value.
template <typename Value>
Shrinkable<typename std::result_of<Value()>::type> lambda(Value &&value);
Shrinkable<typename std::invoke_result<Value>::type> lambda(Value &&value);

/// Creates a `Shrinkable` from an immediate value and an immediate sequence of
/// shrinks.
Expand All @@ -31,7 +31,7 @@ Shrinkable<Decay<T>> just(T &&value);
/// Creates a `Shrinkable` from a callable which returns the value and a
/// callable that returns a `Seq<Shrinkable<T>>` when called with the value.
template <typename Value, typename Shrink>
Shrinkable<typename std::result_of<Value()>::type> shrink(Value &&value,
Shrinkable<typename std::invoke_result<Value>::type> shrink(Value &&value,
Shrink &&shrinkf);

/// Creates a `Shrinkable` from an immediate value and a shrinking callable that
Expand Down
12 changes: 6 additions & 6 deletions include/rapidcheck/shrinkable/Create.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace detail {
template <typename Value, typename Shrink>
class LambdaShrinkable {
public:
using T = Decay<typename std::result_of<Value()>::type>;
using T = Decay<typename std::invoke_result<Value>::type>;

template <typename ValueArg, typename ShrinkArg>
LambdaShrinkable(ValueArg &&value, ShrinkArg &&shrinks)
Expand All @@ -29,7 +29,7 @@ template <typename Value, typename Shrink>
class JustShrinkShrinkable // Yeah I know, weird name
{
public:
using T = Decay<typename std::result_of<Value()>::type>;
using T = Decay<typename std::invoke_result<Value>::type>;

template <typename ValueArg, typename ShrinkArg>
JustShrinkShrinkable(ValueArg &&value, ShrinkArg &&shrinks)
Expand All @@ -49,16 +49,16 @@ class JustShrinkShrinkable // Yeah I know, weird name
// TODO test _all_ of these?

template <typename Value, typename Shrink>
Shrinkable<typename std::result_of<Value()>::type> lambda(Value &&value,
Shrinkable<typename std::invoke_result<Value>::type> lambda(Value &&value,
Shrink &&shrinks) {
using Impl = detail::LambdaShrinkable<Decay<Value>, Decay<Shrink>>;
return makeShrinkable<Impl>(std::forward<Value>(value),
std::forward<Shrink>(shrinks));
}

template <typename Value>
Shrinkable<typename std::result_of<Value()>::type> lambda(Value &&value) {
using T = typename std::result_of<Value()>::type;
Shrinkable<typename std::invoke_result<Value>::type> lambda(Value &&value) {
using T = typename std::invoke_result<Value>::type;
return shrinkable::lambda(std::forward<Value>(value),
fn::constant(Seq<Shrinkable<T>>()));
}
Expand All @@ -75,7 +75,7 @@ Shrinkable<Decay<T>> just(T &&value) {
}

template <typename Value, typename Shrink>
Shrinkable<typename std::result_of<Value()>::type> shrink(Value &&value,
Shrinkable<typename std::invoke_result<Value>::type> shrink(Value &&value,
Shrink &&shrinkf) {
using Impl = detail::JustShrinkShrinkable<Decay<Value>, Decay<Shrink>>;
return makeShrinkable<Impl>(std::forward<Value>(value),
Expand Down
4 changes: 2 additions & 2 deletions include/rapidcheck/shrinkable/Transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace shrinkable {

/// Maps the given shrinkable recursively using the given mapping callable.
template <typename T, typename Mapper>
Shrinkable<Decay<typename std::result_of<Mapper(T)>::type>>
Shrinkable<Decay<typename std::invoke_result<Mapper,T>::type>>
map(Shrinkable<T> shrinkable, Mapper &&mapper);

/// Returns a shrinkable equal to the given shrinkable but with the shrinks
Expand All @@ -26,7 +26,7 @@ Maybe<Shrinkable<T>> filter(Shrinkable<T> shrinkable, Predicate &&pred);
/// `Shrinkable<U>` and returns a `Shrinkable<U>` that shrinks by first
/// shrinking the first value and then shrinking the second value.
template <typename T, typename Mapper>
Shrinkable<typename std::result_of<Mapper(T)>::type::ValueType>
Shrinkable<typename std::invoke_result<Mapper,T>::type::ValueType>
mapcat(Shrinkable<T> shrinkable, Mapper &&mapper);

/// Given two `Shrinkables`, returns a `Shrinkable` pair that first shrinks the
Expand Down
Loading