Tuple is Zero Cost Abstraction?

OFF TOPIC

It seems that a std::tuple is never trivially copyable… :unamused: that sucks!

struct TrivialStruct {
    TrivialStruct (int a, int b, int c) : a_ (a), b_ (b), c_ (c)
    {
    }
    
    int a_;
    int b_;
    int c_;
};

using TrivialTuple = std::tuple<int, int, int>;

static_assert (std::is_trivially_copyable_v<TrivialStruct> == true);
static_assert (std::is_trivially_copyable_v<TrivialTuple>  == false);
1 Like

Not necessarily never, it depends on the implementation of std::tuple

Helpful answer here: c++11 - Why does std::tuple break small-size struct calling convention optimization in C++? - Stack Overflow

1 Like

You are right. It could be, and that seems to be the case in some implementation.

< Reddit - Dive into anything >

I was surprised that it is not required by default.