[DEV] add v1.66.0

This commit is contained in:
2018-01-12 21:47:58 +01:00
parent 87059bb1af
commit a97e9ae7d4
49032 changed files with 7668950 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
# Copyright (C) 2006-2009, 2012 Alexander Nasonov
# Copyright (C) 2012 Lorenzo Caminiti
# Distributed under the Boost Software License, Version 1.0
# (see accompanying file LICENSE_1_0.txt or a copy at
# http://www.boost.org/LICENSE_1_0.txt)
# Home at http://www.boost.org/libs/scope_exit
import testing ;
# Sun does not automatically detect type-of emulation mode (force it).
project : requirements <toolset>sun:<define>BOOST_TYPEOF_EMULATION ;
run try_catch.cpp ;
run try_catch_seq.cpp ;
run try_catch_seq_nova.cpp ;
run scope_guard.cpp ;
run scope_guard_seq.cpp ;
run scope_guard_seq_nova.cpp ;
run world_cxx11_lambda.cpp ;

View File

@@ -0,0 +1,21 @@
// Copyright (C) 2012 Lorenzo Caminiti
// Distributed under the Boost Software License, Version 1.0
// (see accompanying file LICENSE_1_0.txt or a copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Home at http://www.boost.org/libs/scope_exit
#ifndef NOVA_HPP_
#define NOVA_HPP_
#include <boost/config.hpp>
// WARNING: This file must be included first in each compilation unit.
// Force no variadic macros but avoiding macro redefinition warning/error.
#ifndef BOOST_NO_CXX11_VARIADIC_MACROS
# define BOOST_NO_CXX11_VARIADIC_MACROS
#endif
#endif // #include guard

View File

@@ -0,0 +1,46 @@
// Copyright (C) 2006-2009, 2012 Alexander Nasonov
// Copyright (C) 2012 Lorenzo Caminiti
// Distributed under the Boost Software License, Version 1.0
// (see accompanying file LICENSE_1_0.txt or a copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Home at http://www.boost.org/libs/scope_exit
#include <boost/config.hpp>
#ifdef BOOST_NO_CXX11_VARIADIC_MACROS
# error "variadic macros required"
#else
#include <boost/scope_exit.hpp>
#include <boost/typeof/std/string.hpp>
#include <boost/typeof/std/map.hpp>
#include <map>
#include <string>
#include <utility>
int main(void) {
//[scope_guard_decl
bool commit = false;
std::string currency("EUR");
double rate = 1.3326;
std::map<std::string, double> rates;
bool currency_rate_inserted =
rates.insert(std::make_pair(currency, rate)).second;
// Transaction...
//]
//[scope_guard_exit
BOOST_SCOPE_EXIT(currency_rate_inserted, &commit, &rates, &currency) {
if(currency_rate_inserted && !commit) rates.erase(currency);
} BOOST_SCOPE_EXIT_END
// ...
commit = true;
//]
return 0;
}
#endif // variadic macros

View File

@@ -0,0 +1,35 @@
// Copyright (C) 2006-2009, 2012 Alexander Nasonov
// Copyright (C) 2012 Lorenzo Caminiti
// Distributed under the Boost Software License, Version 1.0
// (see accompanying file LICENSE_1_0.txt or a copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Home at http://www.boost.org/libs/scope_exit
#include <boost/scope_exit.hpp>
#include <boost/typeof/std/string.hpp>
#include <boost/typeof/std/map.hpp>
#include <map>
#include <string>
#include <utility>
int main(void) {
bool commit = false;
std::string currency("EUR");
double rate = 1.3326;
std::map<std::string, double> rates;
bool currency_rate_inserted =
rates.insert(std::make_pair(currency, rate)).second;
BOOST_SCOPE_EXIT( (currency_rate_inserted) (&commit) (&rates)
(&currency) ) {
if(currency_rate_inserted && !commit) rates.erase(currency);
} BOOST_SCOPE_EXIT_END
// ...
commit = true;
return 0;
}

View File

@@ -0,0 +1,10 @@
// Copyright (C) 2012 Lorenzo Caminiti
// Distributed under the Boost Software License, Version 1.0
// (see accompanying file LICENSE_1_0.txt or a copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Home at http://www.boost.org/libs/scope_exit
#include "nova.hpp"
#include "scope_guard_seq.cpp"

View File

@@ -0,0 +1,68 @@
// Copyright (C) 2006-2009, 2012 Alexander Nasonov
// Copyright (C) 2012 Lorenzo Caminiti
// Distributed under the Boost Software License, Version 1.0
// (see accompanying file LICENSE_1_0.txt or a copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Home at http://www.boost.org/libs/scope_exit
#include <boost/config.hpp>
#ifdef BOOST_NO_CXX11_VARIADIC_MACROS
# error "variadic macros required"
#else
#include <boost/scope_exit.hpp>
#include <boost/typeof/typeof.hpp>
#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
#include <iostream>
struct file {
file(void) : open_(false) {}
file(char const* path) : open_(false) { open(path); }
void open(char const* path) { open_ = true; }
void close(void) { open_ = false; }
bool is_open(void) const { return open_; }
private:
bool open_;
};
BOOST_TYPEOF_REGISTER_TYPE(file)
void bad(void) {
//[try_catch_bad
file passwd;
try {
passwd.open("/etc/passwd");
// ...
passwd.close();
} catch(...) {
std::clog << "could not get user info" << std::endl;
if(passwd.is_open()) passwd.close();
throw;
}
//]
}
void good(void) {
//[try_catch_good
try {
file passwd("/etc/passwd");
BOOST_SCOPE_EXIT(&passwd) {
passwd.close();
} BOOST_SCOPE_EXIT_END
} catch(...) {
std::clog << "could not get user info" << std::endl;
throw;
}
//]
}
int main(void) {
bad();
good();
return 0;
}
#endif // variadic macros

View File

@@ -0,0 +1,61 @@
// Copyright (C) 2006-2009, 2012 Alexander Nasonov
// Copyright (C) 2012 Lorenzo Caminiti
// Distributed under the Boost Software License, Version 1.0
// (see accompanying file LICENSE_1_0.txt or a copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Home at http://www.boost.org/libs/scope_exit
#include <boost/scope_exit.hpp>
#include <boost/typeof/typeof.hpp>
#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
#include <iostream>
struct file {
file(void) : open_(false) {}
file(char const* path) : open_(false) { open(path); }
void open(char const* path) { open_ = true; }
void close(void) { open_ = false; }
bool is_open(void) const { return open_; }
private:
bool open_;
};
BOOST_TYPEOF_REGISTER_TYPE(file)
void bad(void) {
//[try_catch_bad_seq
file passwd;
try {
passwd.open("/etc/passwd");
// ...
passwd.close();
} catch(...) {
std::clog << "could not get user info" << std::endl;
if(passwd.is_open()) passwd.close();
throw;
}
//]
}
void good(void) {
//[try_catch_good_seq
try {
file passwd("/etc/passwd");
BOOST_SCOPE_EXIT( (&passwd) ) {
passwd.close();
} BOOST_SCOPE_EXIT_END
} catch(...) {
std::clog << "could not get user info" << std::endl;
throw;
}
//]
}
int main(void) {
bad();
good();
return 0;
}

View File

@@ -0,0 +1,10 @@
// Copyright (C) 2012 Lorenzo Caminiti
// Distributed under the Boost Software License, Version 1.0
// (see accompanying file LICENSE_1_0.txt or a copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Home at http://www.boost.org/libs/scope_exit
#include "nova.hpp"
#include "try_catch_seq.cpp"

View File

@@ -0,0 +1,57 @@
// Copyright (C) 2006-2009, 2012 Alexander Nasonov
// Copyright (C) 2012 Lorenzo Caminiti
// Distributed under the Boost Software License, Version 1.0
// (see accompanying file LICENSE_1_0.txt or a copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Home at http://www.boost.org/libs/scope_exit
#include <boost/config.hpp>
#ifdef BOOST_NO_CXX11_LAMBDAS
# error "lambda functions required"
#else
#include <boost/detail/lightweight_test.hpp>
#include <vector>
struct person {};
struct world {
void add_person(person const& a_person);
std::vector<person> persons_;
};
//[world_cxx11_lambda
#include <functional>
struct scope_exit {
scope_exit(std::function<void (void)> f) : f_(f) {}
~scope_exit(void) { f_(); }
private:
std::function<void (void)> f_;
};
void world::add_person(person const& a_person) {
bool commit = false;
persons_.push_back(a_person);
scope_exit on_exit1([&commit, this](void) { // Use C++11 lambda.
if(!commit) persons_.pop_back(); // `persons_` via captured `this`.
});
// ...
commit = true;
}
//]
int main(void) {
world w;
person p;
w.add_person(p);
BOOST_TEST(w.persons_.size() == 1);
return boost::report_errors();
}
#endif // LAMBDAS