Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

something like "decltype(...) xxx"

18 views
Skip to first unread message

Bonita Montero

unread,
Apr 8, 2019, 4:59:05 AM4/8/19
to
I'd like to have a templated class with an iterator-class as a template
-parameter. And internally the class should have a vector having the
element-type the iterator "points" to.
I could write vector<decltype(*it)> when it is a iterator-instance.
But I'd like to have something like vector<decltype(*IteratorType)>.
Theoretically the compiler could deduce the type of *IteratorType
by analyzing the operator * of IteratorType. Even there's the issue
that this type would be a refernce this could work by writing
vector<decltype(remove_reference<*IteratorType>::type). But the
standard doesn't allow all this.
So is there a clever way arround this mess?

Alf P. Steinbach

unread,
Apr 8, 2019, 5:34:02 AM4/8/19
to
Not so clever: `decltype` + `std::declval` + `std::remove_reference_t`.

Clever: `std::iterator_traits`.

Cheers!,

- Alf

0 new messages