Annotated edit history of
Boost version 1, including all changes.
View license author blame.
Rev |
Author |
# |
Line |
1 |
SamJansen |
1 |
Boost is an interesting set of [C++] libraries that can be found at [http://www.boost.org/]. It provides all sorts, from lambda functions to regular expressions. A full list of the libraries included can be found at [http://www.boost.org/libs/libraries.htm]. |
|
|
2 |
|
|
|
3 |
Boost is an example of some of the amazing things which can be accomplised with templates and C++. A few examples shamelessly ripped from the documentation. |
|
|
4 |
|
|
|
5 |
---- |
|
|
6 |
|
|
|
7 |
Lambda functions: |
|
|
8 |
|
|
|
9 |
list<int> v(10); |
|
|
10 |
for_each(v.begin(), v.end(), _1 = 1); |
|
|
11 |
|
|
|
12 |
The expression _1 = 1 creates a lambda functor which assigns the value 1 to every element in v. |
|
|
13 |
|
|
|
14 |
vector<int*> vp(10); |
|
|
15 |
sort(vp.begin(), vp.end(), *_1 > *_2); |
|
|
16 |
|
|
|
17 |
In this call to sort, we are sorting the elements by their contents in descending order. |
|
|
18 |
|
|
|
19 |
---- |
|
|
20 |
|
|
|
21 |
Yes, this is still [C++]. For those interested in Python, perhaps Boost.Python is somewhat useful: |
|
|
22 |
|
|
|
23 |
C++ code: |
|
|
24 |
|
|
|
25 |
struct World |
|
|
26 |
{ |
|
|
27 |
World(std::string msg): msg(msg) {} // added constructor |
|
|
28 |
void set(std::string msg) { this->msg = msg; } |
|
|
29 |
std::string greet() { return msg; } |
|
|
30 |
std::string msg; |
|
|
31 |
}; |
|
|
32 |
|
|
|
33 |
And exporting the class: |
|
|
34 |
|
|
|
35 |
#include <boost/python.hpp> |
|
|
36 |
using namespace boost::python; |
|
|
37 |
|
|
|
38 |
BOOST_PYTHON_MODULE(hello) |
|
|
39 |
{ |
|
|
40 |
class_<World>("World", init<std::string>()) |
|
|
41 |
.def("greet", &World::greet) |
|
|
42 |
.def("set", &World::set) |
|
|
43 |
; |
|
|
44 |
} |
|
|
45 |
|
|
|
46 |
And what it is like in Python: |
|
|
47 |
|
|
|
48 |
>>> import hello |
|
|
49 |
>>> planet = hello.World() |
|
|
50 |
>>> planet.set('howdy') |
|
|
51 |
>>> planet.greet() |
|
|
52 |
'howdy' |
|
|
53 |
|
|
|
54 |
---- |
|
|
55 |
|
|
|
56 |
Not all compilers are able to compile Boost. An interesting read is [http://www.boost.org/status/compiler_status.html] where there are tests done on each compiler to see whether they are able to compile all the boost test cases. |
|
|
57 |
|
|
|
58 |
Boost used a modified Jam as its build system rather than Makefiles. |