Given concept test
which has a function that takes an input range.
template <class T>
concept test = requires(T t, archtypes::Input_Range<T> t_range)
{
{ t.count(t_range) } -> std::same_as<int>;
};
This archtype allows for the count
function to be a template member function.
struct Counter1
{
template<std::ranges::input_range Range>
int count(const Range&);
}
static_assert(test<Counter1>); // passes
Now this satisfies the concept. But I would like this to fail, since this range can be any input range not just input range with int.
Only this should pass
struct Counter2
{
template<std::ranges::input_range Range>
requires std::is_same_v<int,std::ranges::range_value_t<Range>>
int count(const Range&);
}
namespace archetypes
{
// private, only used for concept definitions, NEVER in real code
template <class T>
class InputIterator
{
public:
InputIterator();
~InputIterator();
InputIterator(const InputIterator& other);
InputIterator(InputIterator&& other) noexcept;
InputIterator& operator=(const InputIterator& other);
InputIterator& operator=(InputIterator&& other) noexcept;
using iterator_category = std::input_iterator_tag;
using value_type = T;
using reference = T&;
using pointer = T*;
using difference_type = std::ptrdiff_t;
bool operator==(const InputIterator&) const;
bool operator!=(const InputIterator&) const;
reference operator*() const;
InputIterator& operator++();
InputIterator operator++(int);
};
template <class T>
struct Input_Range
{
Input_Range(const Input_Range& other) = delete;
Input_Range(Input_Range&& other) = delete;
Input_Range& operator=(const Input_Range& other) = delete;
Input_Range& operator=(Input_Range&& other) = delete;
~Input_Range();
using iterator = InputIterator<T>;
iterator begin();
iterator end();
};
}
I can't think of any way to change the concept or archtype so the Counter1
would fail, but Counter2
would pass.