Drake
is_cloneable.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <type_traits>
5 
6 namespace drake {
7 
10 namespace is_cloneable_detail {
11 
12 // Default case; assumes that a class is *not* cloneable.
13 template <typename T, class>
14 struct is_cloneable_helper : std::false_type {};
15 
16 // Special sauce for SFINAE. Only compiles if it can finds the method
17 // `unique_ptr<T> T::Clone() const`. If this exists, the is_cloneable implicitly
18 // prefers this overload over the default overload.
19 template <typename T>
20 struct is_cloneable_helper<
21  T,
22  typename std::enable_if<std::is_same<
23  decltype(std::declval<const T>().Clone().release()),
24  typename std::remove_const<T>::type*>::value>::type>
25  : std::true_type {};
26 
27 } // namespace is_cloneable_detail
28 
76 template <typename T>
77 using is_cloneable =
78  is_cloneable_detail::is_cloneable_helper<T, void>;
79 
80 } // namespace drake
is_cloneable_detail::is_cloneable_helper< T, void > is_cloneable
Definition: is_cloneable.h:78
Definition: automotive_demo.cc:88
STL namespace.