void TestCode() { class aBase { public: aBase(int val=1) : pv_baseVal( val ) {} protected: private: int pv_baseVal; }; class aDerived : public aBase { public: aDerived(int bVal = 1, int val = 1) : aBase( bVal ), pv_derivedVal( val ) {} protected: private: int pv_derivedVal; }; aBase base1(5); aBase base2(3); base1 = base2; aDerived d1(6, 8); aDerived d2(16, 18); d1 = d2; }
/* * Sum of all numbers < 1,000,000 that are palindromic * in base 10 and base 2. */ void eu036(char *ans) { char buf[30]; int t = 0; for (int i = 1; i < 1000000; i++) { sprintf(buf, "%d", i); if (ispalindrome(buf)) { base2(i, buf); if (ispalindrome(buf)) { t += i; } } } sprintf(ans, "%d", t); }
void test_simple_saddle_vertex_mesh() { typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; typedef CGAL::Polyhedron_3<Kernel, CGAL::Polyhedron_items_with_id_3> Polyhedron_3; typedef CGAL::Surface_mesh_shortest_path_traits<Kernel, Polyhedron_3> Traits; typedef Traits::Barycentric_coordinate Barycentric_coordinate; typedef Traits::FT FT; typedef Traits::Point_3 Point_3; typedef Traits::Point_2 Point_2; typedef Traits::Triangle_3 Triangle_3; typedef Traits::Triangle_2 Triangle_2; typedef Traits::Segment_2 Segment_2; typedef boost::graph_traits<Polyhedron_3> Graph_traits; typedef Graph_traits::vertex_descriptor vertex_descriptor; typedef Graph_traits::vertex_iterator vertex_iterator; typedef Graph_traits::halfedge_descriptor halfedge_descriptor; typedef Graph_traits::face_descriptor face_descriptor; typedef CGAL::Surface_mesh_shortest_path<Traits> Surface_mesh_shortest_path; typedef boost::property_map<Polyhedron_3, CGAL::vertex_point_t>::type VPM; Traits traits; Traits::Compute_squared_distance_3 compute_squared_distance_3(traits.compute_squared_distance_3_object()); Traits::Compute_squared_distance_2 compute_squared_distance_2(traits.compute_squared_distance_2_object()); Traits::Construct_triangle_3_along_segment_2_flattening flatten_triangle_3_along_segment_2(traits.construct_triangle_3_along_segment_2_flattening_object()); Traits::Construct_barycentric_coordinate construct_barycentric_coordinate(traits.construct_barycentric_coordinate_object()); std::ifstream inFile("data/saddle_vertex_mesh.off"); Polyhedron_3 P; inFile >> P; inFile.close(); CGAL::set_halfedgeds_items_id(P); vertex_iterator startVertex; vertex_iterator endVertex; boost::tie(startVertex, endVertex) = CGAL::vertices(P); vertex_iterator currentVertex = startVertex; ++currentVertex; vertex_descriptor rootSearchVertex = *currentVertex; face_descriptor currentFace = CGAL::face(CGAL::halfedge(rootSearchVertex, P), P); size_t vertexIndex = CGAL::test::face_vertex_index(currentFace, rootSearchVertex, P); Barycentric_coordinate baryCoord = construct_barycentric_coordinate(vertexIndex == 0 ? FT(1.0) : FT(0.0), vertexIndex == 1 ? FT(1.0) : FT(0.0), vertexIndex == 2 ? FT(1.0) : FT(0.0)); Surface_mesh_shortest_path shortestPaths(P, traits); //shortestPaths.m_debugOutput = true; Surface_mesh_shortest_path::Source_point_iterator firstSourcePoint = shortestPaths.add_source_point(currentFace, baryCoord); shortestPaths.build_sequence_tree(); VPM vpm = CGAL::get(CGAL::vertex_point, P); Point_3 vertexLocations[8]; vertex_descriptor vertexHandles[8]; currentVertex = startVertex; for (size_t i = 0; i < 8; ++i) { vertexHandles[i] = *currentVertex; vertexLocations[i] = vpm[*currentVertex]; ++currentVertex; } FT distanceToBottom = CGAL::sqrt(compute_squared_distance_3(vertexLocations[1], vertexLocations[0])); FT largerSideLength = CGAL::sqrt(compute_squared_distance_3(vertexLocations[1], vertexLocations[2])); FT distanceToSaddle = CGAL::sqrt(compute_squared_distance_3(vertexLocations[1], vertexLocations[4])); FT shorterSideLength = CGAL::sqrt(compute_squared_distance_3(vertexLocations[4], vertexLocations[6])); Triangle_3 lower(vertexLocations[6], vertexLocations[4], vertexLocations[1]); Triangle_3 upper(vertexLocations[4], vertexLocations[6], vertexLocations[7]); Segment_2 base(Point_2(CGAL::ORIGIN), Point_2(shorterSideLength, FT(0.0))); Triangle_2 flatLower(flatten_triangle_3_along_segment_2(lower, 0, base)); Triangle_2 flatUpper(flatten_triangle_3_along_segment_2(upper, 0, Segment_2(base[1], base[0]))); FT distanceToApex = CGAL::sqrt(compute_squared_distance_2(flatLower[2], flatUpper[2])); FT expectedDistances[8] = { distanceToBottom, // a vertex of the larger tetrahedron FT(0.0), // the initial vertex largerSideLength, // a vertex of the larger tetrahedron largerSideLength, // a vertex of the larger tetrahedron distanceToSaddle, // direct line of sight from root distanceToSaddle + shorterSideLength, // around the corner from a pseudo-source (not in direct line of geodesic sight) distanceToSaddle, // direct line of sight from root distanceToApex, }; currentVertex = startVertex; for (size_t i = 0; i < 8; ++i) { CHECK_CLOSE(shortestPaths.shortest_distance_to_source_points(*currentVertex).first, expectedDistances[i], Kernel::FT(0.0001)); ++currentVertex; } // test the edge sequence reporting CGAL::test::Edge_sequence_collector<Traits> collector(P); shortestPaths.shortest_path_sequence_to_source_points(vertexHandles[5], collector); CHECK_EQUAL(collector.m_sequence.size(), 3u); CHECK_EQUAL(collector.m_sequence[1].type, CGAL::test::SEQUENCE_ITEM_VERTEX); assert(collector.m_sequence[1].index == 4 || collector.m_sequence[1].index == 6); CHECK_EQUAL(collector.m_sequence[2].type, CGAL::test::SEQUENCE_ITEM_VERTEX); CHECK_EQUAL(collector.m_sequence[2].index, 1u); collector.m_sequence.clear(); typedef boost::property_map<Polyhedron_3, CGAL::halfedge_external_index_t>::type HalfedgeIndexMap; HalfedgeIndexMap halfedgeIndexMap(CGAL::get(CGAL::halfedge_external_index, P)); shortestPaths.shortest_path_sequence_to_source_points(vertexHandles[7], collector); CHECK_EQUAL(collector.m_sequence.size(), 3u); CHECK_EQUAL(collector.m_sequence[1].type, CGAL::test::SEQUENCE_ITEM_EDGE); CHECK_EQUAL(collector.m_sequence[1].index, halfedgeIndexMap[CGAL::halfedge(vertexHandles[4], vertexHandles[6], P).first]); CHECK_CLOSE(collector.m_sequence[1].edgeAlpha, FT(0.5), FT(0.0001)); CHECK_EQUAL(collector.m_sequence[2].type, CGAL::test::SEQUENCE_ITEM_VERTEX); CHECK_EQUAL(collector.m_sequence[2].index, 1u); // Now test an internal face location sequence halfedge_descriptor firstCrossing = CGAL::halfedge(vertexHandles[4], vertexHandles[7], P).first; size_t edgeIndex = CGAL::internal::edge_index(firstCrossing, P); Barycentric_coordinate location = construct_barycentric_coordinate(0.25, 0.5, 0.25); collector.m_sequence.clear(); shortestPaths.shortest_path_sequence_to_source_points(CGAL::face(firstCrossing, P), construct_barycentric_coordinate(location[edgeIndex], location[(edgeIndex + 1) % 3], location[(edgeIndex + 2) % 3]), collector); CHECK_EQUAL(collector.m_sequence.size(), 4u); CHECK_EQUAL(collector.m_sequence[1].type, CGAL::test::SEQUENCE_ITEM_EDGE); CHECK_EQUAL(collector.m_sequence[1].index, halfedgeIndexMap[firstCrossing]); CHECK_EQUAL(collector.m_sequence[2].type, CGAL::test::SEQUENCE_ITEM_EDGE); CHECK_EQUAL(collector.m_sequence[2].index, halfedgeIndexMap[CGAL::halfedge(vertexHandles[4], vertexHandles[6], P).first]); CHECK_EQUAL(collector.m_sequence[3].type, CGAL::test::SEQUENCE_ITEM_VERTEX); CHECK_EQUAL(collector.m_sequence[3].index, 1u); // Now test with 2 source vertices currentVertex = startVertex; for (size_t i = 0; i < 5; ++i) { ++currentVertex; } vertex_descriptor rootSearchVertex2 = *currentVertex; face_descriptor currentFace2 = CGAL::face(CGAL::halfedge(rootSearchVertex2, P), P); size_t vertexIndex2 = CGAL::test::face_vertex_index(currentFace2, rootSearchVertex2, P); Barycentric_coordinate baryCoord2 = construct_barycentric_coordinate(vertexIndex2 == 0 ? FT(1.0) : FT(0.0), vertexIndex2 == 1 ? FT(1.0) : FT(0.0), vertexIndex2 == 2 ? FT(1.0) : FT(0.0)); Surface_mesh_shortest_path::Source_point_iterator secondSourcePoint = shortestPaths.add_source_point(currentFace2, baryCoord2); shortestPaths.build_sequence_tree(); FT distanceToApexFrom2 = CGAL::sqrt(compute_squared_distance_3(vertexLocations[5], vertexLocations[7])); Triangle_3 lower2(vertexLocations[2], vertexLocations[3], vertexLocations[5]); Triangle_3 upper2(vertexLocations[3], vertexLocations[2], vertexLocations[0]); Segment_2 base2(Point_2(CGAL::ORIGIN), Point_2(largerSideLength, FT(0.0))); Triangle_2 flatLower2(flatten_triangle_3_along_segment_2(lower2, 0, base2)); Triangle_2 flatUpper2(flatten_triangle_3_along_segment_2(upper2, 0, Segment_2(base2[1], base2[0]))); FT distanceToBottom2 = CGAL::sqrt(compute_squared_distance_2(flatLower2[2], flatUpper2[2])); FT expectedDistances2[8] = { distanceToBottom2, // a vertex of the larger tetrahedron FT(0.0), // an initial vertex distanceToSaddle, // a vertex of the larger tetrahedron distanceToSaddle, // a vertex of the larger tetrahedron shorterSideLength, // direct line of sight from root FT(0.0), // around the corner from a pseudo-source (not in direct line of geodesic sight) shorterSideLength, // direct line of sight from root distanceToApexFrom2, }; Surface_mesh_shortest_path::Source_point_iterator expectedSources2[8] = { secondSourcePoint, firstSourcePoint, secondSourcePoint, secondSourcePoint, secondSourcePoint, secondSourcePoint, secondSourcePoint, secondSourcePoint, }; currentVertex = startVertex; for (size_t i = 0; i < 8; ++i) { Surface_mesh_shortest_path::Shortest_path_result result = shortestPaths.shortest_distance_to_source_points(*currentVertex); CHECK_CLOSE(result.first, expectedDistances2[i], Kernel::FT(0.0001)); assert(result.second == expectedSources2[i]); ++currentVertex; } // Test removing a source vertex shortestPaths.remove_source_point(firstSourcePoint); shortestPaths.build_sequence_tree(); // replace the only shortest path which was not reporting to the 2nd source point expectedDistances2[1] = distanceToSaddle + shorterSideLength; currentVertex = startVertex; for (size_t i = 0; i < 8; ++i) { Surface_mesh_shortest_path::Shortest_path_result result = shortestPaths.shortest_distance_to_source_points(*currentVertex); CHECK_CLOSE(result.first, expectedDistances2[i], Kernel::FT(0.0001)); assert(result.second == secondSourcePoint); ++currentVertex; } }
Model* PerlinGenerator::heightmapNonindexed( int udivs, int vdivs, real uSize, real vSize, real normalFindStepRadians ) { Model* model = new Model( "heightmap" ) ; Mesh* mesh = new Mesh( model, MeshType::Nonindexed, VertexType::VT10NC10 ) ; model->addMesh( mesh ) ; real uStep = 1.0 / udivs ; real vStep = 1.0 / vdivs ; // u and v must be normalized to sample the perlin noise function properly // do not use non-integral loop counters, because termination condition is finicky for( int u = 0 ; u < udivs ; u++ ) //x { for( int v = 0 ; v < vdivs ; v++ ) //z { real fu = (real)u/udivs ; real fv = (real)v/vdivs ; // 1- 4 // |/ | // 2- 3 Vector ns[4], cs[4]; Vector c=1;//Vector::random(); for( int i = 0 ; i < 4 ; i++ ) cs[i]=c ; Vector ps[4] = { Vector( u, 0, v ), Vector( u, 0, v+vStep ), Vector( u+uStep, 0, v+vStep ), Vector( u+uStep, 0, v ) } ; for( int i = 0 ; i < 4 ; i++ ) { ps[i].x *= uSize ; ps[i].z *= vSize ; } for( int i = 0 ; i < 4 ; i++ ) ps[i].y = mountainHeight( ps[i].x, ps[i].z ) ; // calculate normals. int nCount = 0 ; for( real ro = 0 ; ro < 2*PI ; ro += normalFindStepRadians ) { nCount++; // rotate about the y-axis, to get points around y1 Vector base1( uStep*uSize/32,0,0 ), base2( uStep*uSize/32,0,0 ) ; // rotation only changes x and z. base1.rotateY( ro ) ; base2.rotateY( ro+normalFindStepRadians ) ; Vector s(1,1,1); //window->addDebugLine( s, Vector(1,0,0), s+base1, Vector(1,0,0) ) ; //window->addDebugLine( s, Vector(1,0,0), s+base2, Vector(1,0,0) ) ; for( int i = 0 ; i < 4 ; i++ ) { // Get the heights base1.y = mountainHeight( ps[i].x + base1.x, ps[i].z + base1.z ) ; base2.y = mountainHeight( ps[i].x + base2.x, ps[i].z + base2.z ) ; // base1 always "lags" base2 ns[i] += base1 × base2 ; window->addDebugLine( ps[i] + base1, Vector(1,0,0), ps[i] + base2, Vector(.5,0,0) ) ; } } for( int i = 0 ; i < 4 ; i++ ) { ns[i] /= nCount ; ns[i].normalize(); // multiply these //ps[i].x *= uSize ; //ps[i].z *= vSize ; } // 0- 3 // |/ | // 1- 2 // add to mesh AllVertex fvs[4] = { AllVertex( ps[0], ns[0], cs[0], 0, 0 ), AllVertex( ps[1], ns[1], cs[1], 0, 0 ), AllVertex( ps[2], ns[2], cs[2], 0, 0 ), AllVertex( ps[3], ns[3], cs[3], 0, 0 ) } ; mesh->addTri( fvs[0],fvs[1],fvs[3] ) ; mesh->addTri( fvs[1],fvs[2],fvs[3] ) ; } } return model ; }
int main(int argc, char const* argv[]) { // printf("_MSC_VER=%d\n", _MSC_VER); singleton_type singleton; pass_value_type pass_value; Moo moo(5); Foo foo; Foo const const_foo = foo; Foo& ref = foo; Foo const& const_ref = const_foo; Foo* ptr = &foo; Foo const* const_ptr = &const_foo; BOOST_ASSERT(false == is_pimpl<Foo>::value); BOOST_ASSERT(false == is_pimpl<int>::value); BOOST_ASSERT(false == is_pimpl<int*>::value); BOOST_ASSERT(false == is_pimpl<int const&>::value); BOOST_ASSERT(true == is_pimpl<Test1>::value); BOOST_ASSERT(false == is_pimpl<Test1*>::value); BOOST_ASSERT(true == is_pimpl<Test2>::value); BOOST_ASSERT(true == is_pimpl<Base>::value); BOOST_ASSERT(true == is_pimpl<Derived1>::value); BOOST_ASSERT(true == is_pimpl<Derived1 const>::value); BOOST_ASSERT(true == is_pimpl<Derived1 const&>::value); Test1 pt11; BOOST_ASSERT(pt11.trace() == "Test1::implementation()"); Test2 vt11; BOOST_ASSERT(vt11.trace() == "Test2::implementation()"); Test1 pt12(5); BOOST_ASSERT(pt12.trace() == "Test1::implementation(int)"); Test2 vt12(5); BOOST_ASSERT(vt12.trace() == "Test2::implementation(int)"); Test1 pt13 = pt12; BOOST_ASSERT(pt13.id() == pt12.id()); // No copying. Implementation shared. Test2 vt13 = vt12; BOOST_ASSERT(vt13.trace() == "Test2::implementation(implementation const&)"); BOOST_ASSERT(vt13.id() != vt12.id()); // Implementation copied. Test1 pt14(pt12); BOOST_ASSERT(pt14.id() == pt12.id()); // No copying. Implementation shared. Test2 vt14(vt12); BOOST_ASSERT(vt14.trace() == "Test2::implementation(implementation const&)"); BOOST_ASSERT(vt14.id() != vt12.id()); // Implementation copied. Test1 pt15(5, 6); BOOST_ASSERT(pt15.trace() == "Test1::implementation(int, int)"); Test1 pt16(singleton); Test1 pt17(singleton); BOOST_ASSERT(pt16.id() == pt17.id()); // No copying. Implementation shared. Test1 pt21(foo); //BOOST_ASSERT(pt21.trace() == "Test1::implementation(Foo&)"); Test1 pt22(const_foo); BOOST_ASSERT(pt22.trace() == "Test1::implementation(Foo const&)"); Test1 pt23(ref); BOOST_ASSERT(pt23.trace() == "Test1::implementation(Foo&)"); Test1 pt24(const_ref); BOOST_ASSERT(pt24.trace() == "Test1::implementation(Foo const&)"); Test1 pt25(ptr); BOOST_ASSERT(pt25.trace() == "Test1::implementation(Foo*)"); Test1 pt26(const_ptr); BOOST_ASSERT(pt26.trace() == "Test1::implementation(Foo const*)"); Test1 pt31(const_foo, const_foo); BOOST_ASSERT(pt31.trace() == "Test1::implementation(Foo const&, Foo const&)"); Test1 pt32(foo, const_foo); BOOST_ASSERT(pt32.trace() == "Test1::implementation(Foo&, Foo const&)"); Test1 pt33(const_foo, foo); BOOST_ASSERT(pt33.trace() == "Test1::implementation(Foo const&, Foo&)"); Test1 pt34(foo, foo); BOOST_ASSERT(pt34.trace() == "Test1::implementation(Foo&, Foo&)"); Test1 pt35(foo, Foo()); BOOST_ASSERT(pt35.trace() == "Test1::implementation(Foo&, Foo const&)"); Test1 pt36(Foo(), foo); BOOST_ASSERT(pt36.trace() == "Test1::implementation(Foo const&, Foo&)"); Test1 pt37(pass_value); BOOST_ASSERT(pt37.trace() == "Test1::implementation(Foo const&)"); //////////////////////////////////////////////////////////////////////////// // Comparisons with 'int'. g++-4.3.4 (linux). //////////////////////////////////////////////////////////////////////////// // The standard behavior. // bool moo_check1 = moo == int(5); // error: no match for ‘operator==’ in ‘moo == 5’ // bool moo_check2 = moo != int(5); // error: no match for ‘operator!=’ in ‘moo != 5’ // bool moo_check3 = int(5) == moo; // error: no match for ‘operator==’ in ‘5 == moo’ // bool moo_check4 = int(5) != moo; // error: no match for ‘operator!=’ in ‘5 != moo’ // The pointer Pimpl behavior. // bool pcheck01 = pt12 == int(5); // error: no match for ‘operator==’ in ‘pt12 == 5’ // bool pcheck02 = pt12 != int(5); // error: no match for ‘operator!=’ in ‘pt12 != 5’ // bool pcheck03 = int(5) == pt12; // error: no match for ‘operator==’ in ‘5 == pt12’ // bool pcheck04 = int(5) != pt12; // error: no match for ‘operator!=’ in ‘5 != pt12’ // The value Pimpl behavior. bool vcheck01 = vt12 == int(5); // Test2 has its own op==(). Non-explicit Test2(int) called. bool vcheck02 = vt12 != int(5); // Test2 has its own op!=(). Non-explicit Test2(int) called. // bool vcheck03 = int(5) == vt12; // error: no match for ‘operator==’ in ‘5 == vt12’ // bool vcheck04 = int(5) != vt12; // error: no match for ‘operator!=’ in ‘5 != vt12’ //////////////////////////////////////////////////////////////////////////// // Comparisons with 'bool'. g++-4.3.4 (linux). //////////////////////////////////////////////////////////////////////////// // The standard behavior. bool moo_check5 = moo == false; // Deploys operator safebool::type() conversion bool moo_check6 = moo != false; // Deploys operator safebool::type() conversion bool moo_check7 = false == moo; // Deploys operator safebool::type() conversion bool moo_check8 = false != moo; // Deploys operator safebool::type() conversion // The pointer Pimpl behavior. bool pcheck05 = pt12 == false; // Deploys operator safebool::type() conversion bool pcheck06 = pt12 != false; // Deploys operator safebool::type() conversion bool pcheck07 = false == pt12; // Deploys operator safebool::type() conversion bool pcheck08 = false != pt12; // Deploys operator safebool::type() conversion // The value Pimpl behavior. // bool vcheck05 = vt12 == false; // Test2 has its own op==(). error: ambiguous overload for ‘operator==’ in ‘vt12 == false’ // bool vcheck06 = vt12 != false; // Test2 has its own op!=(). error: ambiguous overload for ‘operator!=’ in ‘vt12 != false’ bool vcheck07 = false == vt12; // Deploys operator safebool::type() conversion bool vcheck08 = false != vt12; // Deploys operator safebool::type() conversion //////////////////////////////////////////////////////////////////////////// // Comparisons with Pimpl. g++-4.3.4 (linux). //////////////////////////////////////////////////////////////////////////// bool pcheck1 = pt12 == pt13; // calls pimpl_base::op==() bool pcheck2 = pt12 != pt13; // calls pimpl_base::op!=() bool vcheck1 = vt12 == vt13; // calls Test2::op==() bool vcheck2 = vt12 != vt13; // calls Test2::op!=() if ( moo) {} // Check it calls conversion to safebool. if ( !moo) {} // Check it calls conversion to safebool. if ( pt11) {} // Check it calls conversion to safebool. if (!pt11) {} // Check it calls conversion to safebool. if ( vt11) {} // Check it calls conversion to safebool. if (!vt11) {} // Check it calls conversion to safebool. { // Testing swap(). int pt16_id = pt16.id(); int pt17_id = pt17.id(); int vt13_id = vt13.id(); int vt14_id = vt14.id(); pt16.swap(pt17); vt13.swap(vt14); BOOST_ASSERT(pt16.id() == pt17_id); BOOST_ASSERT(pt17.id() == pt16_id); BOOST_ASSERT(vt13.id() == vt14_id); BOOST_ASSERT(vt14.id() == vt13_id); } int k11 = vt11.get(); BOOST_ASSERT(k11 == 0); int k12 = vt12.get(); BOOST_ASSERT(k12 == 5); int k13 = vt13.get(); BOOST_ASSERT(k13 == 5); vt14.set(33); BOOST_ASSERT(vt12 == vt13); // Good: Only compiles if op==() is part of Test2 interface. BOOST_ASSERT(vt12.trace() == "Test2::operator==(Test2 const&)"); BOOST_ASSERT(vt11 != vt12); // Good: Only compiles if op==() is part of Test2 interface. BOOST_ASSERT(vt11.trace() == "Test2::operator==(Test2 const&)"); { // Testing run-time polymorphic behavior. Base base1 (1); Derived1 derived1 (2, 3); Derived2 derived2 (2, 3, 4); Base base2 (derived1); // calls copy constructor Base base3 (derived2); // calls copy constructor Base base4 (Derived2(2,3,4)/*const ref to temporary*/); // calls copy constructor Derived1 bad1 (pimpl<Derived1>::null()); Derived2 bad2 (pimpl<Derived2>::null()); Base* bp1 = &base1; Base* bp2 = &base2; Base* bp3 = &base3; Base* bp4 = &derived1; Base* bp5 = &derived2; Base* bp6 = &bad1; Base* bp7 = &bad2; Base bad_base1 = Base::null(); Base bad_base2 = pimpl<Base>::null(); // Base bad_base3 = pimpl<Foo>::null(); // correctly does not compile. // Foo bad_foo = pimpl<Foo>::null(); // correctly does not compile. Derived1 bad_derived1 = pimpl<Derived1>::null(); Derived2 bad_derived2 = pimpl<Derived2>::null(); bool check1 = base1 == derived1; bool check2 = base1 == derived2; bool check3 = derived1 == base1; bool check4 = derived2 == base1; if ( bad1) BOOST_ASSERT(0); if (!bad2) BOOST_ASSERT(1); base2.call_virtual(); BOOST_ASSERT(base2.trace() == "Derived1::call_virtual()"); base3.call_virtual(); BOOST_ASSERT(base3.trace() == "Derived2::call_virtual()"); bp1->call_virtual(); BOOST_ASSERT(bp1->trace() == "Base::call_virtual()"); bp2->call_virtual(); BOOST_ASSERT(bp2->trace() == "Derived1::call_virtual()"); bp3->call_virtual(); BOOST_ASSERT(bp3->trace() == "Derived2::call_virtual()"); bp4->call_virtual(); BOOST_ASSERT(bp4->trace() == "Derived1::call_virtual()"); bp5->call_virtual(); BOOST_ASSERT(bp5->trace() == "Derived2::call_virtual()"); // bp6->call_virtual(); // crash. referencing bad1 // bp7->call_virtual(); // crash. referencing bad1 } #ifdef __linux__ { printf("BEG: Testing pimpl and boost::serialization.\n"); Test1 saved (12345); std::ofstream ofs ("filename"); boost::archive::text_oarchive oa (ofs); printf("Calling boost::archive::test_oarchive << Test1.\n"); oa << *(Test1 const*) &saved; // write class instance to archive ofs.close(); std::ifstream ifs ("filename", std::ios::binary); boost::archive::text_iarchive ia (ifs); Test1 restored (Test1::null()); // Implementation will be replaced. printf("Calling boost::archive::test_iarchive >> Test1.\n"); ia >> restored; // read class state from archive assert(saved.get() == restored.get()); printf("END: Testing pimpl and boost::serialization.\n"); } #endif printf("Pimpl test has successfully completed.\n"); return 0; }
size_t euler::problem36() { assert( base2( 585 ) == "1001001001" ); assert( is_double_base_palindrome( 585 ) ); return boost::accumulate( boost::irange( 1_u, 1e6_u ) | boost::adaptors::filtered( &is_double_base_palindrome ), 0_u ); }