concepts: add legacy_input_iterator and legacy_iterator

This commit is contained in:
Danny Robson 2020-02-18 12:18:05 +11:00
parent c001502aa2
commit 706e77f44a

View File

@ -9,6 +9,7 @@
#pragma once #pragma once
#include <type_traits> #include <type_traits>
#include <iterator>
#include <utility> #include <utility>
@ -170,6 +171,56 @@ namespace cruft::concepts {
{ a.max_size () } -> same_as<typename T::size_type>; { a.max_size () } -> same_as<typename T::size_type>;
{ a.empty () } -> boolean; { a.empty () } -> boolean;
}; };
template <typename T>
concept move_assignable =
requires (T a, T b)
{
{ a = std::move (b) } -> same_as<T&>;
};
template <typename T>
concept copy_assignable =
move_assignable<T> &&
requires (T a, T b)
{
{ a = b } -> same_as<T&>;
};
template <typename T>
concept legacy_iterator =
copy_constructible<T> &&
copy_assignable<T> &&
destructible<T> &&
swappable<T> &&
requires (T t)
{
typename std::iterator_traits<T>::value_type;
typename std::iterator_traits<T>::difference_type;
typename std::iterator_traits<T>::reference;
typename std::iterator_traits<T>::pointer;
typename std::iterator_traits<T>::iterator_category;
{ *t };
{ ++t } -> same_as<T&>;
};
template <typename T>
concept legacy_input_iterator =
legacy_iterator<T> &&
equality_comparable<T> &&
requires (T a, T b)
{
typename std::iterator_traits<T>::reference;
typename std::iterator_traits<T>::value_type;
{ a != b } -> boolean;
{ ++a } -> same_as<T&>;
{ a++ };
};
} }