Why are my two tuples containing strings, created the same way, not equal?

You are comparing pointers to buffers of characters, not strings.

Sometimes the compiler will turn two different "one"s into the same buffer, sometimes it will not.

In your case, it isn't. Probably a debug build.

Add #include <string_view>, then

using namespace std::literals;

auto t1 = std::make_tuple("one"sv, "two"sv, "three"sv);
auto t2 = std::make_tuple("one"sv, "two"sv, "three"sv);

and you'll get what you expect. (In pre-c++17 compilers, use <string> and ""s instead of <string_view> and ""sv).


What is the type of "one"? This is not a string, but rather a string literal.

Your problem basically boils down to this code:

char const* a = "one";
char const* b = "one";

std::cout << "(a == b) is " << std::boolalpha << (a == b) << "\n";
std::cout << "(a != b) is " << std::boolalpha << (a != b) << "\n";

Which will most likely output the same result.

This is because a string literal will decay into a char const*. Comparing two pointer compares their location in memory. Now this is a matter of whether your compiler is folding string literals into one. If the string literals are folded, then they are gonna be equal, if they are not, they are not gonna be equal. This can vary with different optimization levels.

How can you fix your comparison then?

Preferably use std::string_view as you don't seem to need to own or change their content:

using namespace std::literals;

// ... 

auto t1 = std::make_tuple("one"sv, "two"sv, "three"sv);
auto t2 = std::make_tuple("one"sv, "two"sv, "three"sv);

The std::string_view class is a thin wrapper around a pointer and a size, and define a comparison operator that check for value equality.