Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterator zero incrementing leads to assert on empty vector. #83

Closed
Klayflash opened this issue Sep 11, 2018 · 3 comments
Closed

Iterator zero incrementing leads to assert on empty vector. #83

Klayflash opened this issue Sep 11, 2018 · 3 comments

Comments

@Klayflash
Copy link

This construction leads to assert:

  auto it = v.begin(); // empty vector
  it += 0; // <---- assert here

See also b56cbb6
Full code:


#include <boost/container/vector.hpp>
#include <vector>
#include <assert.h>

#define TEST_ASSERT(x) assert((x))

typedef int StorableType;

typedef std::vector<StorableType> StdVector;
typedef boost::container::vector<StorableType> BoostVector;

template<typename Vector>
void insertToPosition(Vector& v,size_t pos,StorableType val)
{
  auto it = v.begin();
  it += pos;
  v.insert(it,val);
}

template<typename Vector>
void test()
{
  // insert to begin and non empty
  {
    Vector v = {11,12};
    insertToPosition(v,0,10);
    TEST_ASSERT((v == Vector{10,11,12}));
  }
  // insert to empty
  {
    Vector v;
    insertToPosition(v,0,10);
    TEST_ASSERT((v == Vector{10}));
  }
}


int main()
{
  test<StdVector>();
  test<BoostVector>();

  return 0;
}
@AL1ve1T
Copy link

AL1ve1T commented Oct 17, 2018

Please, can you give more detailed description about that issue?

@Klayflash
Copy link
Author

Klayflash commented Oct 17, 2018

If you run this code then

test<BoostVector>();

call will give you boost assert.

test<StdVector>();

runs without assert.

@igaztanaga
Copy link
Member

Many thanks for the report. Fixed in the following commit, to be released in Boost 1.69:

10a618a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants