Main Page
Namespaces
Classes
Package Documentation
src
FWCore
Utilities
interface
get_underlying_safe.h
Go to the documentation of this file.
1
#ifndef FWCore_Utilities_get_underlying_safe_h
2
#define FWCore_Utilities_get_underlying_safe_h
3
4
/*
5
Description:
6
7
The function get_underlying(), provided by propagate_const, should not be called directly
8
by users because it may cast away constness.
9
This header provides helper function(s) get_underlying_safe() to users of propagate_const<T>.
10
The get_underlying_safe() functions avoid this issue.
11
12
If called with a non-const ref argument, get_underlying_safe() simply calls get_underlying().
13
If called with a const ref argument, get_underlying_safe() returns a pointer to const,
14
which preserves constness, but requires copying the pointer.
15
16
For non-copyable pointers, such as std::unique_ptr, it is not possible to preserve constness.
17
so get_underlying_safe() will fail to compile if called with a const ref to a unique_ptr.
18
This is intentional.
19
20
This header can be expanded to support other smart pointers as needed.
21
*/
22
23
//
24
// Original Author: Bill Tanenbaum
25
//
26
27
// system include files
28
#include <memory>
29
30
// user include files
31
32
#include "
FWCore/Utilities/interface/propagate_const.h
"
33
34
// forward declarations
35
36
namespace
edm
{
37
38
// for std::shared_ptr
39
template
<
typename
T>
40
std::shared_ptr<T>&
get_underlying_safe
(
propagate_const
<std::shared_ptr<T>>& iP) {
41
return
get_underlying
(iP);
42
}
43
template
<
typename
T>
44
std::shared_ptr<T const>
get_underlying_safe
(
propagate_const
<std::shared_ptr<T>>
const
& iP) {
45
std::shared_ptr<T const>
copy
=
get_underlying
(iP);
46
return
copy
;
47
}
48
49
// for bare pointer
50
template
<
typename
T>
51
T
*&
get_underlying_safe
(
propagate_const<T*>
& iP) {
52
return
get_underlying
(iP);
53
}
54
template
<
typename
T>
55
T
const
*
get_underlying_safe
(
propagate_const<T*>
const
& iP) {
56
T
const
*
copy
=
get_underlying
(iP);
57
return
copy
;
58
}
59
60
// for std::unique_ptr
61
template
<
typename
T>
62
std::unique_ptr<T>&
get_underlying_safe
(
propagate_const
<std::unique_ptr<T>>& iP) {
63
return
get_underlying
(iP);
64
}
65
// This template below will deliberately not compile.
66
template
<
typename
T>
67
std::unique_ptr<T const>
get_underlying_safe
(
propagate_const
<std::unique_ptr<T>>
const
& iP) {
68
std::unique_ptr<T const>
copy
=
get_underlying
(iP);
69
return
copy
;
70
}
71
72
}
// namespace edm
73
74
#endif
edm::propagate_const
Definition:
propagate_const.h:32
popcon2dropbox.copy
def copy(args, dbName)
Definition:
popcon2dropbox.py:122
edm::get_underlying
T & get_underlying(propagate_const< T > &)
Definition:
propagate_const.h:83
edm::get_underlying_safe
std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
Definition:
get_underlying_safe.h:40
edm
HLT enums.
Definition:
AlignableModifier.h:17
T
long double T
Definition:
Basic3DVectorLD.h:66
propagate_const.h
Generated for CMSSW Reference Manual by
1.8.11