C++ – 常用 Debug 工具代码

类生命周期及常用运算符追踪器

struct FTracker
{
    FTracker()                                               { std::cout << "FTracker()"                                   << std::endl;               }
    FTracker(const FTracker&)                                { std::cout << "FTracker(const FTracker&)"                    << std::endl;               }
    FTracker(FTracker&&)                                     { std::cout << "FTracker(FTracker&&)"                         << std::endl;               }
    ~FTracker()                                              { std::cout << "~FTracker()"                                  << std::endl;               }
    FTracker& operator=(const FTracker&)                     { std::cout << "operator=(const FTracker&)"                   << std::endl; return *this; }
    FTracker& operator=(FTracker&&)                          { std::cout << "operator=(FTracker&&)"                        << std::endl; return *this; }
    friend bool operator==(const FTracker&, const FTracker&) { std::cout << "operator==(const FTracker&, const FTracker&)" << std::endl; return  true; }
};

类型生命周期及常用运算符萃取信息

using Type = TTuple<int32, double>;

std::cout << TIsDefaultConstructible<Type>::Value          << std::endl;
std::cout << TIsTriviallyDefaultConstructible<Type>::Value << std::endl;
std::cout << TIsConstructible<Type>::Value                 << std::endl;
std::cout << TIsTriviallyConstructible<Type>::Value        << std::endl;
std::cout << TIsCopyConstructible<Type>::Value             << std::endl;
std::cout << TIsTriviallyCopyConstructible<Type>::Value    << std::endl;
std::cout << TIsMoveConstructible<Type>::Value             << std::endl;
std::cout << TIsTriviallyMoveConstructible<Type>::Value    << std::endl;
std::cout << TIsCopyAssignable<Type>::Value                << std::endl;
std::cout << TIsTriviallyCopyAssignable<Type>::Value       << std::endl;
std::cout << TIsMoveAssignable<Type>::Value                << std::endl;
std::cout << TIsTriviallyMoveAssignable<Type>::Value       << std::endl;
std::cout << TIsDestructible<Type>::Value                  << std::endl;
std::cout << TIsTriviallyDestructible<Type>::Value         << std::endl;

发表回复