Skip to content
Open
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
13 changes: 12 additions & 1 deletion include/rapidcheck/Gen.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <type_traits>
#include <cassert>

#include "rapidcheck/detail/Any.h"
Expand All @@ -17,6 +18,13 @@ Gen<Decay<typename std::result_of<Mapper(T)>::type>> map(Gen<T> gen,

} // namespace gen

// Concept check for types that have method
// `Shrinkable<T> G::operator()(const Random &, int) const`
template<typename T, typename G>
using MakesShrinkable = std::is_convertible<
decltype(std::declval<const G>()(std::declval<Random>(), 0)),
Shrinkable<T>>;

template <typename T>
class Gen<T>::IGenImpl {
public:
Expand Down Expand Up @@ -55,7 +63,10 @@ class Gen<T>::GenImpl : public IGenImpl {
template <typename T>
template <typename Impl, typename>
Gen<T>::Gen(Impl &&impl)
: m_impl(new GenImpl<Decay<Impl>>(std::forward<Impl>(impl))) {}
: m_impl(new GenImpl<Decay<Impl>>(std::forward<Impl>(impl))) {
static_assert(MakesShrinkable<T, Decay<Impl>>::value,
"Generator implementation must have a method Shrinkable<T> operator()(const Random &, int) const");
}

template <typename T>
std::string Gen<T>::name() const {
Expand Down