Skip to content

Bug(?): small_vector ignores stored_size #341

Description

@matcibula

Hello, small_vector seems to be ignoring stored_size option, and instead always using size_t. Reading documentation, it seems to me that this should not be the case. Am I missing something or is this a bug? Thank you for your time.

(tested on 1.91 release (GCC 16.1), based on changelog and github issues, this wasn't changed for 1.92)
minimal reproducible example:

#include <boost/container/small_vector.hpp>
#include <boost/container/vector.hpp>
#include <boost/container/options.hpp>
#include <iostream>

using namespace boost::container;

int main()
{
  using vo = vector_options_t<stored_size<uint16_t>>;
  using svo_16 = small_vector_options_t<stored_size<uint16_t>>;
  using svo_32 = small_vector_options_t<stored_size<uint32_t>>;
  using svo_64 = small_vector_options_t<stored_size<uint64_t>>;

  // Expected sizeof(v1) == 16;
  vector<int16_t, void, vo> v1;
  // Expected sizeof(v2) == 16;
  small_vector<int16_t, 2, void, svo_16> v2;
  // Expected sizeof(v3) == 24;
  small_vector<int16_t, 2, void, svo_32> v3;
  // Expected sizeof(v4) == 32;
  small_vector<int16_t, 2, void, svo_64> v4;

  std::cout << sizeof(decltype(v1)) << "\n"; // OK Returns 16
  std::cout << sizeof(decltype(v2)) << "\n"; // ERROR(?) Returns 32, expected 16
  std::cout << sizeof(decltype(v3)) << "\n"; // ERROR(?) Returns 32, expected 24
  std::cout << sizeof(decltype(v4)) << "\n"; // OK Returns 32
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions