emplace_constructible.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef TEST_SUPPORT_EMPLACE_CONSTRUCTIBLE_H
  2. #define TEST_SUPPORT_EMPLACE_CONSTRUCTIBLE_H
  3. #include "test_macros.h"
  4. #if TEST_STD_VER >= 11
  5. template <class T>
  6. struct EmplaceConstructible {
  7. T value;
  8. explicit EmplaceConstructible(T xvalue) : value(xvalue) {}
  9. EmplaceConstructible(EmplaceConstructible const&) = delete;
  10. };
  11. template <class T>
  12. struct EmplaceConstructibleAndMoveInsertable {
  13. int copied = 0;
  14. T value;
  15. explicit EmplaceConstructibleAndMoveInsertable(T xvalue) : value(xvalue) {}
  16. EmplaceConstructibleAndMoveInsertable(
  17. EmplaceConstructibleAndMoveInsertable&& Other)
  18. : copied(Other.copied + 1), value(std::move(Other.value)) {}
  19. };
  20. template <class T>
  21. struct EmplaceConstructibleAndMoveable {
  22. int copied = 0;
  23. int assigned = 0;
  24. T value;
  25. explicit EmplaceConstructibleAndMoveable(T xvalue) noexcept : value(xvalue) {}
  26. EmplaceConstructibleAndMoveable(EmplaceConstructibleAndMoveable&& Other)
  27. noexcept : copied(Other.copied + 1),
  28. value(std::move(Other.value)) {}
  29. EmplaceConstructibleAndMoveable&
  30. operator=(EmplaceConstructibleAndMoveable&& Other) noexcept {
  31. copied = Other.copied;
  32. assigned = Other.assigned + 1;
  33. value = std::move(Other.value);
  34. return *this;
  35. }
  36. };
  37. template <class T>
  38. struct EmplaceConstructibleMoveableAndAssignable {
  39. int copied = 0;
  40. int assigned = 0;
  41. T value;
  42. explicit EmplaceConstructibleMoveableAndAssignable(T xvalue) noexcept
  43. : value(xvalue) {}
  44. EmplaceConstructibleMoveableAndAssignable(
  45. EmplaceConstructibleMoveableAndAssignable&& Other) noexcept
  46. : copied(Other.copied + 1),
  47. value(std::move(Other.value)) {}
  48. EmplaceConstructibleMoveableAndAssignable&
  49. operator=(EmplaceConstructibleMoveableAndAssignable&& Other) noexcept {
  50. copied = Other.copied;
  51. assigned = Other.assigned + 1;
  52. value = std::move(Other.value);
  53. return *this;
  54. }
  55. EmplaceConstructibleMoveableAndAssignable& operator=(T xvalue) {
  56. value = std::move(xvalue);
  57. ++assigned;
  58. return *this;
  59. }
  60. };
  61. #endif
  62. #endif // TEST_SUPPORT_EMPLACE_CONSTRUCTIBLE_H