Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
wire-cell-build
util
test
test_any.cxx
Go to the documentation of this file.
1
#include <boost/any.hpp>
2
#include <memory>
3
#include <iostream>
4
5
using namespace
std
;
6
7
struct
Base
{
8
virtual
~Base
() {}
9
int
b
;
10
};
11
struct
Foo
:
public
Base
{
12
virtual
~Foo
() {}
13
int
a
;
14
};
15
16
enum
DFPMeta
{
notdfp
,
eos
,
restart
};
17
18
int
main
()
19
{
20
boost::any aobj;
21
{
22
aobj = std::make_shared<Foo>();
23
}
24
auto
base
= boost::any_cast<std::shared_ptr<Foo> >(aobj);
25
26
if
(!base) {
27
cerr <<
"base is null\n"
;
28
}
29
else
{
30
cerr <<
"base is not null\n"
;
31
}
32
33
boost::any what =
eos
;
34
if
(
eos
== boost::any_cast<DFPMeta>(what)) {
35
cerr <<
"Got eos from eos\n"
;
36
}
37
38
DFPMeta
dfpm;
39
try
{
40
dfpm = boost::any_cast<
DFPMeta
>(aobj);
41
}
42
catch
(boost::bad_any_cast &
e
) {
43
std::cerr <<
"aobj not a DFPMeta: "
<< e.what() <<
'\n'
;
44
dfpm =
notdfp
;
45
}
46
cerr <<
"DFPMeta = "
<< dfpm <<
"\n"
;
47
48
return
0;
49
50
}
restart
Definition:
test_any.cxx:16
Base
Definition:
value_ptr_test.cc:17
Base::b
int b
Definition:
test_any.cxx:9
Foo
Foo.
Definition:
064_castoperator.cpp:20
Foo::a
int a
Definition:
test_any.cxx:13
notdfp
Definition:
test_any.cxx:16
base
Definition:
value_ptr_test_4.cc:8
std
STL namespace.
e
const double e
Definition:
gUpMuFluxGen.cxx:165
eos
Definition:
test_any.cxx:16
Base::~Base
virtual ~Base()
Definition:
test_any.cxx:8
main
int main()
Definition:
test_any.cxx:18
DFPMeta
DFPMeta
Definition:
test_any.cxx:16
Foo::~Foo
virtual ~Foo()
Definition:
test_any.cxx:12
Generated by
1.8.11