summaryrefslogtreecommitdiff
path: root/libs/utility/identity_type/test/template.cpp
blob: dfc10979580f2158ce7d0bbdfaaa79bc9d1a879c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

// Copyright (C) 2009-2012 Lorenzo Caminiti
// Distributed under the Boost Software License, Version 1.0
// (see accompanying file LICENSE_1_0.txt or a copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Home at http://www.boost.org/libs/utility/identity_type

#include <boost/utility/identity_type.hpp>
#include <map>
#include <iostream>

//[template_f_decl
#define ARG(type, n) type arg ## n

template<typename T>
void f( // Prefix macro with `typename` in templates.
    ARG(typename BOOST_IDENTITY_TYPE((std::map<int, T>)), 1)
) {
    std::cout << arg1[0] << std::endl;
}
//]

//[template_g_decl
template<typename T>
void g(
    std::map<int, T> arg1
) {
    std::cout << arg1[0] << std::endl;
}
//]

int main() {
    //[template_f_call
    std::map<int, char> a;
    a[0] = 'a';
    
    f<char>(a); // OK...
    // f(a);    // ... but error.
    //]

    //[template_g_call
    g<char>(a); // OK...
    g(a);       // ... and also OK.
    //]
    
    return 0;
}