Skip to content

Commit c7ff016

Browse files
committed
doc
1 parent 745685a commit c7ff016

25 files changed

+827
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) 2018-2025 Jean-Louis Leroy
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// See accompanying file LICENSE_1_0.txt
4+
// or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
6+
// tag::content[]
7+
#include "roles.hpp"
8+
#include <boost/openmethod.hpp>
9+
10+
BOOST_OPENMETHOD_OVERRIDE(
11+
pay, (boost::openmethod::virtual_ptr<const Employee>), double) {
12+
return 5000.0;
13+
}
14+
15+
BOOST_OPENMETHOD_CLASSES(Employee)
16+
// end::content[]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2018-2025 Jean-Louis Leroy
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// See accompanying file LICENSE_1_0.txt
4+
// or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
6+
// tag::content[]
7+
// main.cpp
8+
9+
#include "roles.hpp"
10+
#include <iostream>
11+
12+
#include <boost/openmethod/initialize.hpp>
13+
14+
int main() {
15+
boost::openmethod::initialize();
16+
17+
Employee bill;
18+
Salesman bob; bob.sales = 100'000.0;
19+
20+
std::cout << "pay bill: $" << pay(bill) << "\n"; // pay bill: $5000
21+
std::cout << "pay bob: $" << pay(bob) << "\n"; // pay bob: $10000
22+
}
23+
// end::content[]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2018-2025 Jean-Louis Leroy
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// See accompanying file LICENSE_1_0.txt
4+
// or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
6+
// tag::content[]
7+
// roles.hpp
8+
9+
#ifndef ROLES_HPP
10+
#define ROLES_HPP
11+
12+
#include <boost/openmethod.hpp>
13+
14+
struct Employee { virtual ~Employee() = default; };
15+
16+
struct Salesman : Employee {
17+
double sales = 0.0;
18+
};
19+
20+
BOOST_OPENMETHOD(pay, (boost::openmethod::virtual_ptr<const Employee>), double);
21+
22+
#endif // ROLES_HPP
23+
// end::content[]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) 2018-2025 Jean-Louis Leroy
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// See accompanying file LICENSE_1_0.txt
4+
// or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
6+
// tag::content[]
7+
#include "roles.hpp"
8+
#include <boost/openmethod.hpp>
9+
10+
BOOST_OPENMETHOD_OVERRIDE(
11+
pay, (boost::openmethod::virtual_ptr<const Salesman> emp), double) {
12+
return next(emp) + emp->sales * 0.05; // base + commission
13+
}
14+
15+
BOOST_OPENMETHOD_CLASSES(Employee, Salesman)
16+
17+
// end::content[]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) 2018-2025 Jean-Louis Leroy
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// See accompanying file LICENSE_1_0.txt
4+
// or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
6+
// tag::content[]
7+
#include "roles.hpp"
8+
#include <boost/openmethod.hpp>
9+
10+
BOOST_OPENMETHOD_DEFINE_OVERRIDER(
11+
pay, (boost::openmethod::virtual_ptr<const Employee>), double) {
12+
return 5000.0;
13+
}
14+
15+
BOOST_OPENMETHOD_CLASSES(Employee)
16+
// end::content[]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2018-2025 Jean-Louis Leroy
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// See accompanying file LICENSE_1_0.txt
4+
// or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
6+
// tag::content[]
7+
// main.cpp
8+
9+
#include "roles.hpp"
10+
#include <iostream>
11+
12+
#include <boost/openmethod/initialize.hpp>
13+
14+
int main() {
15+
boost::openmethod::initialize();
16+
17+
Employee bill;
18+
Salesman bob; bob.sales = 100'000.0;
19+
20+
std::cout << "pay bill: $" << pay(bill) << "\n"; // pay bill: $5000
21+
std::cout << "pay bob: $" << pay(bob) << "\n"; // pay bob: $10000
22+
}
23+
// end::content[]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2018-2025 Jean-Louis Leroy
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// See accompanying file LICENSE_1_0.txt
4+
// or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
6+
// tag::content[]
7+
// roles.hpp
8+
9+
#ifndef ROLES_HPP
10+
#define ROLES_HPP
11+
12+
#include <boost/openmethod.hpp>
13+
14+
struct Employee { virtual ~Employee() = default; };
15+
16+
struct Salesman : Employee {
17+
double sales = 0.0;
18+
};
19+
20+
BOOST_OPENMETHOD(pay, (boost::openmethod::virtual_ptr<const Employee>), double);
21+
22+
BOOST_OPENMETHOD_DECLARE_OVERRIDER(
23+
pay, (boost::openmethod::virtual_ptr<const Employee>), double);
24+
25+
26+
#endif // ROLES_HPP
27+
// end::content[]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2018-2025 Jean-Louis Leroy
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// See accompanying file LICENSE_1_0.txt
4+
// or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
6+
#include "roles.hpp"
7+
#include <boost/openmethod.hpp>
8+
9+
// tag::content[]
10+
BOOST_OPENMETHOD_OVERRIDE(
11+
pay, (boost::openmethod::virtual_ptr<const Salesman> emp), double) {
12+
return BOOST_OPENMETHOD_OVERRIDER(
13+
pay, (boost::openmethod::virtual_ptr<const Employee> emp),
14+
double)::fn(emp) +
15+
emp->sales * 0.05; // base + commission
16+
}
17+
// end::content[]
18+
19+
BOOST_OPENMETHOD_CLASSES(Employee, Salesman)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) 2018-2025 Jean-Louis Leroy
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// See accompanying file LICENSE_1_0.txt
4+
// or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
6+
// tag::content[]
7+
#include "roles.hpp"
8+
#include <boost/openmethod.hpp>
9+
10+
BOOST_OPENMETHOD_CLASSES(Employee)
11+
// end::content[]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2018-2025 Jean-Louis Leroy
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// See accompanying file LICENSE_1_0.txt
4+
// or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
6+
// tag::content[]
7+
// main.cpp
8+
9+
#include "roles.hpp"
10+
#include <iostream>
11+
12+
#include <boost/openmethod/initialize.hpp>
13+
14+
int main() {
15+
boost::openmethod::initialize();
16+
17+
Employee bill;
18+
Salesman bob; bob.sales = 100'000.0;
19+
20+
std::cout << "pay bill: $" << pay(bill) << "\n"; // pay bill: $5000
21+
std::cout << "pay bob: $" << pay(bob) << "\n"; // pay bob: $10000
22+
}
23+
// end::content[]

0 commit comments

Comments
 (0)