Q:

map::const_iterator mapped type is not const

I'm trying to write an iterator adaptor for a class built on top of a map. I'm having issue when trying to get the mapped type from the iterator type. Basically I'd like to get:

map<Key,Val>::iterator --> Val
map<Key,Val>::const_iterator --> Val const

Here is a minimal repro.
#include <map>
#include <type_traits>
    
template <typename BaseIteratorT>
using ValueType = typename BaseIteratorT::value_type::second_type;
    
// Passes
static_assert(
    std::is_same<ValueType<std::map<double, int>::iterator>, int>::value,
    "bad type for mutable iterator");

// Fails
static_assert(
    std::is_same<ValueType<std::map<double, int>::const_iterator>, const int>::value,
    "bad type for const iterator");

How can I achieve that (C++14)?

A:

For almost all practical purposes, types you might want to deduce is tied to some expression, in which case decltype is always the answer
template<typename T>
using mapped_type = std::remove_reference_t<decltype((std::declval<T>()->second))>;

using m = std::map<char, int>;
using i = mapped_type<m::iterator>  // int
using ci = mapped_type<m::const_iterator>  // const int

