Classes | Enumerations | Functions
test_any.cxx File Reference
#include <boost/any.hpp>
#include <memory>
#include <iostream>

Go to the source code of this file.

Classes

struct  Base
 
class  Foo
 Foo. More...
 

Enumerations

enum  DFPMeta { notdfp, eos, restart }
 

Functions

int main ()
 

Enumeration Type Documentation

enum DFPMeta
Enumerator
notdfp 
eos 
restart 

Definition at line 16 of file test_any.cxx.

16 { notdfp, eos, restart };
Definition: test_any.cxx:16

Function Documentation

int main ( void  )

Definition at line 18 of file test_any.cxx.

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 }
const double e
Definition: test_any.cxx:16
DFPMeta
Definition: test_any.cxx:16