The difference between const and non const key

So I start thinking about what's the difference between this 2 code
 
map<const int, float> map_data;

 
map<int, float> map_data;

But it seems I can't find the difference, is there any difference between this 2 code ?
std::map< const int, float > and std::map< int, float > are two different types.

Other than that, there is no difference; the key in a map is a const anyway.
The value_type of std::map<KEY,DATA> is std::pair< const KEY, DATA >

1
2
3
4
5
6
7
8
9
10
11
template < typename T > struct A
{
    A() = default ;
    A( const T& k ) : key(k) {}

    const T key = T() ;
};

A<int> a ; // type of a.key is const int
A< const int > a2 ; // type of a2.key is const int
                    //  'const const T' collapses to 'const T' 

Last edited on
Topic archived. No new replies allowed.