Since std::vector contains a constructor constructor that accepts std::initializer_list , you can use uniform initialization syntax if the sameTwoVectors function accepts a vector by value, rvalue reference, or const .
namespace Util { bool sameTwoVectors( const std::vector<int>& result, const std::vector<int>& expected) { return result == expected; } } int main() { std::vector<int> result; EXPECT_TRUE(Util::sameTwoVectors(result, {5,2,3,15})); }
Optionally, if sameTwoVectors performs only a simple comparison, you can eliminate it. Just use the comparison expression in its place when you call EXPECT_TRUE . The trade-off is that you must explicitly specify std::vector<int> rather than relying on the implicit conversion constructor. These are a few characters smaller and a little clearer what the expected result is.
EXPECT_TRUE(result == std::vector<int>({5,2,3,15}));
source share