Skip to content

Instantly share code, notes, and snippets.

@boki1
Created July 8, 2021 09:28
Show Gist options
  • Save boki1/d4bd98c7b0ad9aa083148cf30ebc08eb to your computer and use it in GitHub Desktop.
Save boki1/d4bd98c7b0ad9aa083148cf30ebc08eb to your computer and use it in GitHub Desktop.
Concepts require iterator/range inside
#include <type_traits>
#include <thread>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
#include <concepts>
#include <variant>
#include <iostream>
#include <iterator>
#include <ranges>
// template <typename T>
// concept iterable_type_inside = requires (T x, T::inner_seq inner_seq_it) {
// typename T::inner_type;
// typename T::inner_seq;
// typename T::inner_seq::iterator;
// requires std::input_iterator<typename T::inner_seq::iterator>;
// requires std::same_as<int, std::iter_value_t<typename T::inner_seq::iterator>>;
// { x.goo() } -> std::same_as<int>;
// };
template <typename T>
concept cas_with_version = true;
template <typename T>
concept iterable_type_inside = requires (T x, T::inner_seq inner_seq_it) {
typename T::inner_type;
typename T::inner_seq;
requires std::ranges::input_range<typename T::inner_seq>;
requires cas_with_version<std::ranges::range_value_t<typename T::inner_seq>>;
{ x.goo() } -> std::same_as<int>;
};
struct ok {
using inner_type = int;
using inner_seq = std::vector<ok::inner_type>;
int goo() const { return 0; }
};
struct not_ok {
using inner_type = int;
using inner_seq = int;
constexpr int goo() const { return 0; }
};
struct not_ok_2 {
using inner_type = int;
using inner_seq = std::vector<double>;
constexpr int goo() const { return 0; }
};
template <iterable_type_inside T>
constexpr auto foo(const T& t) {
return t.goo();
}
int main(int, const char *[]) {
auto lambda = [](std::weakly_incrementable auto t) {};
std::vector<int> vec{1, 2, 3};
lambda(vec.begin());
foo(ok{});
// foo(not_ok{});
// foo(not_ok_2{});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment