test_fret.cxx
Go to the documentation of this file.
1 #include <iostream>
2 #include <functional>
3 #include <random>
4 
5 typedef std::function<int()> intsrc_t;
6 
7 struct MyIntFunc {
8  int number = 0;
9  MyIntFunc(int n=0) : number(n) {}
10  int operator()() { return number; }
11 };
12 
14 {
15  MyIntFunc mif(42);
16  return mif;
17 }
18 
20 {
21  std::cerr << f() << std::endl;
22 }
23 
24 std::default_random_engine make_a_generator()
25 {
26  std::default_random_engine generator(42);
27  std::uniform_real_distribution<double> distribution(0.0,1.0);
28  std::cerr << "Made generator with " << distribution(generator) << std::endl;
29  return generator;
30 }
31 std::default_random_engine take_a_generator(std::default_random_engine generator)
32 {
33  std::uniform_real_distribution<double> distribution(0.0,1.0);
34  std::cerr << "Take generator with " << distribution(generator) << std::endl;
35  return generator;
36 }
37 
38 int main()
39 {
40  MyIntFunc f(666);
41  take_a_func(f);
42 
44  take_a_func(f2);
45 
46  std::default_random_engine generator = make_a_generator();
47  std::uniform_real_distribution<double> distribution(0.0,1.0);
48  std::cerr << "Used generator with " << distribution(generator) << std::endl;
49  generator = take_a_generator(generator);
50  std::cerr << "Copy generator with " << distribution(generator) << std::endl;
51  generator = take_a_generator(generator);
52  std::cerr << "Copy generator with " << distribution(generator) << std::endl;
53 }
intsrc_t return_a_func()
Definition: test_fret.cxx:13
void take_a_func(intsrc_t f)
Definition: test_fret.cxx:19
int main()
Definition: test_fret.cxx:38
SynchrotronAndGN f2
int operator()()
Definition: test_fret.cxx:10
int number
Definition: test_fret.cxx:8
std::default_random_engine take_a_generator(std::default_random_engine generator)
Definition: test_fret.cxx:31
generator
Definition: train.py:468
MyIntFunc(int n=0)
Definition: test_fret.cxx:9
std::function< int()> intsrc_t
Definition: test_fret.cxx:5
std::default_random_engine make_a_generator()
Definition: test_fret.cxx:24
std::size_t n
Definition: format.h:3399
QTextStream & endl(QTextStream &s)