2

The boost::mpl::push_back documentation states that:

push_back performs an insertion at the end of the sequence with guaranteed O(1) complexity.

Is it complexity of compilation time?

Luc Touraille
  • 79,925
  • 15
  • 92
  • 137
mirt
  • 1,453
  • 1
  • 17
  • 35

2 Answers2

4

Yes of course. It works with types, not with values.

The Boost.MPL library is a general-purpose, high-level C++ template metaprogramming framework of compile-time algorithms, sequences and metafunctions

ForEveR
  • 55,233
  • 2
  • 119
  • 133
0

The O(1) refers to complexity during runtime. Usually, procedures which execute in O(1) time are said to execute in constant time. In this case, the documentation claims that the time needed for push_back to execute is constant with respect to the length of the list; that is, its execution time will be a fixed constant time independent of the list's length.

On the other hand, if the documentation had claimed that push_back executed with O(n) complexity, that would have indicated that push_back's execution time could be approximated by a linear function of the list's length, where the list's length here is n. Functions that fall in this complexity category are said to execute in linear time.

Wikipedia has a good introduction to the O(n) notation [1]. A good introductory text is "An Introduction to Algorithms" by Cormen, Lieverson, and Rivest.

Chadversary
  • 852
  • 8
  • 11
  • Thank you for detailed explanation about O-notation. I was confused that this runtime parameter was applied to compiletime methods. For me the question is about terminology. Such things don't actually executes in runtime. I mean we could say that keyword 'class' takes O(1) as well. – mirt Nov 08 '12 at 13:12