typeid.name

The function typeid.name can give us the information about variable.

Header file:
typeinfo

#include <typeinfo>

int main()
{
    vector<bool> vec{ false, true };

    auto ans = vec[0];
    cout << typeid(ans).name() << endl;

    bool tmp = false;
    cout << typeid(tmp).name() << endl;

    int value = 12;
    cout << typeid(value).name() << endl;

    return 0;
}

/*
St14_Bit_reference
b
i
*/

The output meanings:

bool:                     b
char:                     c
signed char:              a
unsigned char:            h
(signed) short (int):     s
unsigned short (int):     t
(signed) (int):           i
unsigned (int):           j
(signed) long (int):      l
unsigned long (int):      m
(signed) long long (int): x
unsigned long long (int): y
float:                    f
double:                   d
long double:              e

initializer_list

Use initializer_list to append multiple elements for container.

#include <initializer_list>

using namespace std;

class Base{
public:
    void Append( initializer_list<int> elements ){
        values.insert( values.end(), elements.begin(), elements.end() );
    }
    void Print(){
        for( auto value: values ){
            cout << value << "\t";
        }
    }

protected:
    vector<int> values;
};


int main()
{
    Base obj;
    obj.Append( { 1,2,3,4,5 } );
    obj.Print();
    return 0;
}

The difference of constructors for braces and square brackets.

void Print( std::vector<int> &v ){
    for( auto value: v ){
        cout << value << "\t";
    }
    cout << endl;
}


int main()
{
    std::vector<int> v0{ 10, 20 };
    Print( v0 );
    std::vector<int> v1( 10, 20 );
    Print( v1 );
    return 0;
}
/*
10      20
20      20      20      20      20      20      20      20      20      20
*/

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Image Processing: support to flip your image.

X
A prohibited operation
0
Would love your thoughts, please comment.x
()
x