[Bug c++/82171] New: Cant use std::declval in concept testing map operator[]
rwdougla at gmail dot com
gcc-bugzilla@gcc.gnu.org
Mon Sep 11 01:27:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82171
Bug ID: 82171
Summary: Cant use std::declval in concept testing map
operator[]
Product: gcc
Version: 7.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: rwdougla at gmail dot com
Target Milestone: ---
static_assert fires inside c++/7.2.0/type_traits:2259:7
Godbolt link: https://godbolt.org/g/raan9j
Pasted here: (compiler flags are -std=c++1z -fconcepts)
#include <utility>
#include <type_traits>
#include <iterator>
template<typename T>
concept bool MapLike = requires(T t) {
{t[std::declval<typename T::value_type::first_type>()]}
-> typename T::value_type::second_type;
};
void test(MapLike T) {}
#include <map>
#include <vector>
int main() {
test(std::map<int, int>{});
//test(std::vector<std::pair<int, int>>{});
}
Workaround requires bankshot through nested requirement:
https://godbolt.org/g/j7kuKF
#include <utility>
#include <type_traits>
#include <iterator>
template<typename MapT, typename ValueT>
concept bool HasIndexOp = requires (MapT t, ValueT v) {
{ t[v] } -> typename MapT::value_type::second_type;
};
template<typename T>
concept bool MapLike = requires(T t) {
requires HasIndexOp<T, typename T::value_type::first_type>;
};
void test(MapLike T) {}
#include <map>
#include <vector>
int main() {
test(std::map<int, int>{});
//test(std::vector<std::pair<int, int>>{});
}
More information about the Gcc-bugs
mailing list