// Copyright (C) 2013 Vicente Botet // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include #include #include #include #include #if 1 struct B { int v; B(int i) : v(i) {} }; struct D: B { D(int i) : B(i) {} }; void fb(B const&) {} void fd(D const&) {} BOOST_STATIC_ASSERT(sizeof(B)==sizeof(D)); template > class new_vector; template class new_vector : public std::vector { typedef std::vector base_type; public: new_vector() : base_type() {} new_vector(unsigned s) : base_type(s) {} }; template class new_vector { //std::vector::other > v; int i; public: }; template typename std::enable_if::value, new_vector& >::type new_vector_cast(std::vector & v) { return reinterpret_cast&>(v); } BOOST_STATIC_ASSERT(sizeof(std::vector)==sizeof(new_vector)); BOOST_STATIC_ASSERT(sizeof(std::vector)!=sizeof(new_vector)); void fb(std::vector const&) {} void fd(new_vector const&) {} int main() { { std::vector b(1); b[0] = 1; new_vector d = new_vector_cast(b); BOOST_ASSERT(b[0] == d[0]); } { //std::vector b; //new_vector d = new_vector_cast(b); // compile fail } { std::vector b(1); b[0] = 1; fd(new_vector_cast(b)); } { new_vector d(1); d[0] = 1; std::vector b = d; BOOST_ASSERT(b[0] == d[0]); } { //new_vector d; //std::vector b = d; // compile fail } { new_vector d(1); d[0] = 1; fd(d); } return 0; } #else int main() { { B b(1); D d = reinterpret_cast(b); BOOST_ASSERT(b.v == d.v); } { B b(1); fd(reinterpret_cast(b)); } { D d(2); B b = d; BOOST_ASSERT(b.v == d.v); } { D d(2); fd(d); } return 0; } #define BOOST_THREAD_VERSION 4 #include #include int calculate_the_answer_to_life_the_universe_and_everything() { return 42; } int main() { boost::packaged_task pt(calculate_the_answer_to_life_the_universe_and_everything); boost::shared_future fi1 = boost::shared_future(pt.get_future()); boost::shared_future fi2 = fi1; boost::thread task(boost::move(pt)); // launch task on a thread boost::wait_for_any(fi1, fi2); std::cout << "Wait for any returned\n"; return (0); } #endif