I'm trying to use concepts in order to be able to detect if a given type's begin function returns an iterator to "const T&" or just to "T&". But I'm not sure how one would best go about it, I have tried the following:
#include <iostream>
#include <concepts>
#include <vector>
#include <set>
template <typename T>
concept IsConst = std::is_const<T>::value;
template<typename T>
concept IsIterableOfConst = requires (T& t) { { *t.begin() } -> IsConst; };
template <IsIterableOfConst T>
void test()
{
std::cout << "Yes" << std::endl;
}
template <typename T>
void test()
{
std::cout << "No" << std::endl;
}
int main(int argc, char** argv)
{
test<std::set<int>>();
test<std::vector<int>>();
}
This produces the output "No No" when I would expect it to produce the output "Yes No" as iterators in std::set should, as far as I'm aware, always iterate over "const" versions of the sets held type. How do I correctly detect that the container contains const values?