Search code examples
c++c++14std-pairstdinitializerlist

Why can't std::pair be compared to std::initiliazer_list


For std::pair, I am just curious to know why this works

std::pair<int, int> response = {1, 2}

while, this doesn't:

if (response == {1, 2}) do something;

Is it because the operator = is overloaded for std::pair while == isn't?


Solution

  • This is just syntax: braced-init-list can be an operand only to [] and () (on the inside) and = and any @= (on the right). The initialization case is also allowed, where there is no operator at all.