mardi 28 février 2017

Use operator== and initializer-list

For example

template<class Container, class T>
bool operator==(Container const& c, std::initializer_list<T> const& l)
{
    return c.size() == l.size() && equal(c.begin(), c.end(), l.begin());
}

Check by

std::vector<int> v = {1, 2};
bool b = operator==(v, {1, 2}); // okay
b = (v == {1, 2}); // Error

Why? and How to fix it?

Aucun commentaire:

Enregistrer un commentaire