File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#pragma once
22
3+ #include < type_traits>
34#include < cassert>
45
56#include " rapidcheck/detail/Any.h"
@@ -17,6 +18,13 @@ Gen<Decay<typename std::result_of<Mapper(T)>::type>> map(Gen<T> gen,
1718
1819} // namespace gen
1920
21+ // Concept check for types that have method
22+ // `Shrinkable<T> G::operator()(const Random &, int) const`
23+ template <typename T, typename G>
24+ using MakesShrinkable = std::is_convertible<
25+ decltype (std::declval<const G>()(std::declval<Random>(), 0 )),
26+ Shrinkable<T>>;
27+
2028template <typename T>
2129class Gen <T>::IGenImpl {
2230public:
@@ -55,7 +63,10 @@ class Gen<T>::GenImpl : public IGenImpl {
5563template <typename T>
5664template <typename Impl, typename >
5765Gen<T>::Gen(Impl &&impl)
58- : m_impl(new GenImpl<Decay<Impl>>(std::forward<Impl>(impl))) {}
66+ : m_impl(new GenImpl<Decay<Impl>>(std::forward<Impl>(impl))) {
67+ static_assert (MakesShrinkable<T, Decay<Impl>>::value,
68+ " Generator implementation must have a method Shrinkable<T> operator()(const Random &, int) const" );
69+ }
5970
6071template <typename T>
6172std::string Gen<T>::name() const {
You can’t perform that action at this time.
0 commit comments