Advertisement
STANAANDREY

forwarding

May 18th, 2025
481
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #if defined(_MSC_VER)
  2. #include <__msvc_all_public_headers.hpp>
  3. #elif defined(__GNUC__)
  4. #include <bits/stdc++.h>
  5. #else
  6. #error "Unsupported compiler"
  7. #endif
  8. using namespace std;
  9.  
  10. class Integer {
  11. public:
  12.     Integer() {
  13.         pval = new int(0);
  14.         cout << "Integer()" << endl;
  15.     }
  16.     Integer(int value) {
  17.         pval = new int(value);
  18.         cout << "Integer(int)" << endl;
  19.     }
  20.     Integer(const Integer& other) {
  21.         pval = new int(*other.pval);
  22.         cout << "Integer(const Integer&)" << endl;
  23.     }
  24.     Integer(Integer&& other) noexcept {
  25.         pval = other.pval;
  26.         other.pval = nullptr;
  27.         cout << "Integer(Integer&&)" << endl;
  28.     }
  29.     int get() const {
  30.         return *pval;
  31.     }
  32.     ~Integer() {
  33.         delete pval;
  34.         cout << "~Integer()" << endl;
  35.     }
  36. private:
  37.     int* pval = nullptr;
  38. };
  39.  
  40. class Entity {
  41. public:
  42.     template <typename T1, typename T2>
  43.     Entity(T1&& id, T2&& name) : id(forward<T1>(id)), name(forward<T2>(name)) {
  44.         cout << "Entity(T1&&, T2&&)" << endl;
  45.     }
  46.  
  47.     template <typename T1, typename T2>
  48.     static Entity* create(T1&& id, T2&& name) {
  49.         return new Entity{ forward<T1>(Integer{ id }), name };
  50.     }
  51. private:
  52.     Integer id;
  53.     string name;
  54. };
  55.  
  56. int main() {
  57.     Entity e1{ Integer{1}, "Alice" };
  58.     return 0;
  59. }
  60.  
Advertisement
Comments
  • dutmdh
    5 days
    # text 0.29 KB | 0 0
    1. Leon West Accidental Goblin King Audiobooks 1-4
    2.  
    3. magnet:?xt=urn:btih:49d386821d7a4093ac6209084242fbdf979b0ac1
    4. magnet:?xt=urn:btih:9f49b631081256fdab2d7b13927ce27bd44cf683
    5. magnet:?xt=urn:btih:6ef04c5cd32428d63afbca8a5b754688082059d3
    6. magnet:?xt=urn:btih:feae4390a335f0743bc8852d70183ace64240e1a
Add Comment
Please, Sign In to add comment
Advertisement