File: decltype.cc

package info (click to toggle)
c%2B%2B-annotations 13.02.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,576 kB
  • sloc: cpp: 25,297; makefile: 1,523; ansic: 165; sh: 126; perl: 90; fortran: 27
file content (97 lines) | stat: -rw-r--r-- 2,011 bytes parent folder | download | duplicates (5)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <iostream>
#include <string>
#include <vector>
#include <type_traits>

using namespace std;

int &&rref();
int const &icref();

string const &text()
{
    static string txt = "text";
    return txt;
}

void fun(string const &text)
{
    auto s1{text};
    decltype(text) s2 = text;
}

struct Data
{
    vector<string> d_vs;
    string i_val;
    string *d_val = new string[10];

    Data()
    :
        d_vs(1)
    {}

    decltype(auto) vs() const
    {
        return d_vs[0];
    }

    decltype(auto) dt() const
    {
        return d_val[0];
    }

    auto au() const                 // returns: string
    {
        string &sr = d_val[0];
        return d_val[0];
    }

    auto vs2() const                 // returns: string
    {
        string const &sr = d_vs[0];
        return d_vs[0];
    }

};

int main()
{

//    int value = 12;
//    int *ip = &value;
//
//    int *const &ptr = ip;
//    auto ptr2 = ptr;        // int *
//
//    decltype(auto) ptr3 = ptr2;
//
//    cout << is_same< int *, decltype(ptr3) >::value << '\n';
//
//    decltype(auto) ptr4 = (ptr2);
//
//    cout << is_same< int * &, decltype(ptr4) >::value << '\n';
//
//    decltype(auto) ret = value + value;
//    cout << is_same< int, decltype(ret) >::value << '\n';
//
//    string lines[20];
//    decltype(auto) line = lines[0];
//    cout << is_same< string &, decltype(line) >::value << '\n';

//    decltype(auto) ref = string{};
//    cout << is_same< string, decltype(ref) >::value << '\n';

    Data data;
    cout << is_same< string const &, decltype(data.vs()) >::value << '\n';

//    cout << is_same< int *, decltype(ptr2) >::value << '\n';
//    cout << is_same< int * &, decltype((ptr2)) >::value << '\n';
//    cout << is_same< int, decltype((value + value)) >::value << '\n';
//
//    string &&strRref = string{};
//    decltype(strRref) lref = string{};
//
//    cout << is_same< string &&, decltype(lref) >::value << '\n';
//    cout << is_same< string &, decltype((lref)) >::value << '\n';
}