All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cxxCast.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_BASE_TF_CXX_CAST_H
8#define PXR_BASE_TF_CXX_CAST_H
9
12
13#ifndef __cplusplus
14#error This include file can only be included in C++ programs.
15#endif
16
17#include "pxr/pxr.h"
18#include <type_traits>
19
20PXR_NAMESPACE_OPEN_SCOPE
21
22template <class Src, class Dst>
23using Tf_CopyConst =
24 typename std::conditional<std::is_const<Src>::value,
25 typename std::add_const<Dst>::type, Dst>::type;
26
27template <class Src, class Dst>
28using Tf_CopyVolatile =
29 typename std::conditional<std::is_volatile<Src>::value,
30 typename std::add_volatile<Dst>::type, Dst>::type;
31
32template <class Src, class Dst>
33using Tf_CopyCV = Tf_CopyConst<Src, Tf_CopyVolatile<Src, Dst>>;
34
47template <typename T>
48inline typename std::enable_if<
49 std::is_polymorphic<T>::value, Tf_CopyCV<T, void>*>::type
51{
52 return dynamic_cast<Tf_CopyCV<T, void>*>(ptr);
53}
54
55template <typename T>
56inline typename std::enable_if<
57 !std::is_polymorphic<T>::value, Tf_CopyCV<T, void>*>::type
59{
60 return static_cast<Tf_CopyCV<T, void>*>(ptr);
61}
62
63PXR_NAMESPACE_CLOSE_SCOPE
64
65#endif
std::enable_if< std::is_polymorphic< T >::value, Tf_CopyCV< T, void > * >::type TfCastToMostDerivedType(T *ptr)
Return a pointer to the most-derived object.
Definition: cxxCast.h:50