mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-19 11:18:40 +08:00

Run the `clang-format.bash` script to update all our C and C++ code to a new style defined by `.clang-format`. Use `clang-format` version 15. * If you reached this commit for a line in `git blame`, re-run the blame operation starting at the parent of this commit to see older history for the content. * See the parent commit for instructions to rebase a change across this style transition commit. Fixes: #24315
66 lines
1.1 KiB
C++
66 lines
1.1 KiB
C++
#include <iostream>
|
|
#include <memory>
|
|
|
|
#include <cmext/memory>
|
|
|
|
namespace {
|
|
class Base
|
|
{
|
|
public:
|
|
virtual ~Base() = default;
|
|
};
|
|
|
|
class Derived : public Base
|
|
{
|
|
public:
|
|
~Derived() override = default;
|
|
|
|
void method() {}
|
|
};
|
|
|
|
template <typename T>
|
|
class Wrapper
|
|
{
|
|
public:
|
|
Wrapper(T* v)
|
|
: value(v)
|
|
{
|
|
}
|
|
~Wrapper() { delete this->value; }
|
|
|
|
T* get() const { return this->value; }
|
|
|
|
private:
|
|
T* value;
|
|
};
|
|
|
|
bool testReferenceCast()
|
|
{
|
|
std::cout << "testReferenceCast()" << std::endl;
|
|
|
|
std::unique_ptr<Base> u(new Derived);
|
|
cm::static_reference_cast<Derived>(u).method();
|
|
cm::dynamic_reference_cast<Derived>(u).method();
|
|
|
|
std::shared_ptr<Base> s(new Derived);
|
|
cm::static_reference_cast<Derived>(s).method();
|
|
cm::dynamic_reference_cast<Derived>(s).method();
|
|
|
|
// can also be used with custom wrappers
|
|
Wrapper<Base> w(new Derived);
|
|
cm::static_reference_cast<Derived>(w).method();
|
|
cm::dynamic_reference_cast<Derived>(w).method();
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
int testCMExtMemory(int /*unused*/, char* /*unused*/[])
|
|
{
|
|
if (!testReferenceCast()) {
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|