Skip to content

How to create a vector with a non-copyable struct? #822

Closed Answered by jwellbelove
ricardomatias asked this question in Q&A
Discussion options

You must be logged in to vote

This works.

#include "etl/vector.h"

struct NonCopyable
{
  NonCopyable(int i_)
    : i(i)
  {
  }

  NonCopyable(NonCopyable&&) = default;
  NonCopyable& operator =(NonCopyable&&) = default;

  NonCopyable(const NonCopyable&) = delete;
  NonCopyable& operator =(const NonCopyable&) = delete;

  int i;
};

int main()
{
  etl::vector<NonCopyable, 2> v;

  v.emplace_back(NonCopyable{ 1 });
  v.emplace_back(NonCopyable{ 2 });
}

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ricardomatias
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants