Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is std::tuple required to use empty base class optimization?

Tags:

c++

Will

std::is_empty<std::tuple<Args...>>::value

return true if every type in Args is empty? A quick test in gcc 4.9 indicates that this is the case but is it required by the standard?

like image 464
MadScientist Avatar asked Oct 25 '25 12:10

MadScientist


1 Answers

No, there's no requirement that tuple use inheritance to enable the empty base class optimisation.

The only textual specification of the tuple library is:

This subclause describes the tuple library that provides a tuple type as the class template tuple that can be instantiated with any number of arguments. Each template argument specifies the type of an element in the tuple. Consequently, tuples are heterogeneous, fixed-size collections of values. An instantiation of tuple with two arguments is similar to an instantiation of pair with the same two arguments.

with no mention of any implementation details; and the template specification begins:

template <class... Types>
class tuple {

not specifying that it must inherit from anything.

like image 145
Mike Seymour Avatar answered Oct 28 '25 04:10

Mike Seymour