doc_emplace.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2009-2013. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/container for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #include <boost/container/detail/config_begin.hpp>
  11. #include <boost/container/detail/workaround.hpp>
  12. //[doc_emplace
  13. #include <boost/container/list.hpp>
  14. #include <cassert>
  15. //Non-copyable and non-movable class
  16. class non_copy_movable
  17. {
  18. non_copy_movable(const non_copy_movable &);
  19. non_copy_movable& operator=(const non_copy_movable &);
  20. public:
  21. non_copy_movable(int = 0) {}
  22. };
  23. int main ()
  24. {
  25. using namespace boost::container;
  26. //Store non-copyable and non-movable objects in a list
  27. list<non_copy_movable> l;
  28. non_copy_movable ncm;
  29. //A new element will be built calling non_copy_movable(int) constructor
  30. l.emplace(l.begin(), 0);
  31. assert(l.size() == 1);
  32. //A new element will be value initialized
  33. l.emplace(l.begin());
  34. assert(l.size() == 2);
  35. return 0;
  36. }
  37. //]
  38. #include <boost/container/detail/config_end.hpp>