Example #1
0
int main( int argc, char * argv[])
{
    {
        boost::coroutines::asymmetric_coroutine< void >::pull_type source1( boost::bind( first, _1) );
        boost::coroutines::asymmetric_coroutine< void >::pull_type source2( boost::bind( second, _1) );
        while ( source1 && source2) {
            source1();
            std::cout << " ";
            source2();
            std::cout << " ";
        }
    }

    std::cout << "\nDone" << std::endl;

    return EXIT_SUCCESS;
}
double QgsCoordinateTransform::scaleFactor( const QgsRectangle &ReferenceExtent ) const
{
  QgsPointXY source1( ReferenceExtent.xMinimum(), ReferenceExtent.yMinimum() );
  QgsPointXY source2( ReferenceExtent.xMaximum(), ReferenceExtent.yMaximum() );
  double distSourceUnits = std::sqrt( source1.sqrDist( source2 ) );
  QgsPointXY dest1 = transform( source1 );
  QgsPointXY dest2 = transform( source2 );
  double distDestUnits = std::sqrt( dest1.sqrDist( dest2 ) );
  return distDestUnits / distSourceUnits;
}
Example #3
0
int main()
{
    {
        typedef std::unique_ptr<A> APtr;
        APtr s(new A);
        A* p = s.get();
        APtr s2 = std::move(s);
        assert(s2.get() == p);
        assert(s.get() == 0);
        assert(A::count == 1);
    }
    assert(A::count == 0);
    {
        typedef Deleter<A> MoveDel;
        typedef std::unique_ptr<A, MoveDel> APtr;
        MoveDel d(5);
        APtr s(new A, std::move(d));
        assert(d.state() == 0);
        assert(s.get_deleter().state() == 5);
        A* p = s.get();
        APtr s2 = std::move(s);
        assert(s2.get() == p);
        assert(s.get() == 0);
        assert(A::count == 1);
        assert(s2.get_deleter().state() == 5);
        assert(s.get_deleter().state() == 0);
    }
    assert(A::count == 0);
    {
        typedef NCDeleter<A> NonCopyDel;
        typedef std::unique_ptr<A, NonCopyDel&> APtr;

        NonCopyDel d;
        APtr s(new A, d);
        A* p = s.get();
        APtr s2 = std::move(s);
        assert(s2.get() == p);
        assert(s.get() == 0);
        assert(A::count == 1);
        d.set_state(6);
        assert(s2.get_deleter().state() == d.state());
        assert(s.get_deleter().state() ==  d.state());
    }
    assert(A::count == 0);
    {
       sink1(source1());
       assert(A::count == 0);
       sink2(source2());
       assert(A::count == 0);
       sink3(source3());
       assert(A::count == 0);
    }
    assert(A::count == 0);
}
void exercise_constructor(unsigned int dim){
	std::cout << "Dimension " << dim << '\n';
	const size_t size=dim*dim;
	const double initVal=3.14;
	
	SU_vector source1(dim);
	source1.SetAllComponents(initVal);
	
	std::unique_ptr<double[]> buffer(new double[size]);
	for(unsigned int i=0; i<size; i++)
		buffer[i]=initVal;
	SU_vector source2(dim,buffer.get());
	
	std::cout << "Internal storage\n";
	alloc_counting::reset_allocation_counters();
	SU_vector dest1(source1);
	auto allocated=alloc_counting::mem_allocated;
	std::cout << allocated/sizeof(double) << " entries allocated" << '\n';
	//check the number of components
	auto components=dest1.GetComponents();
	std::cout << components.size() << " components stored" << '\n';
	//check that all components are initialized to the correct value
	std::cout << "components " <<
		(std::all_of(components.begin(),components.end(),[=](double c){ return(c==initVal); })?
		 "are":"are not") << " correctly set\n";
	//check that memory is not aliased
	source1[0]=0;
	std::cout << "Memory aliasing: " << (dest1[0]==source1[0]) << '\n';
	
	std::cout << "External storage\n";
	alloc_counting::reset_allocation_counters();
	SU_vector dest2(source2);
	allocated=alloc_counting::mem_allocated;
	std::cout << allocated/sizeof(double) << " entries allocated" << '\n';
	//check the number of components
	components=dest2.GetComponents();
	std::cout << components.size() << " components stored" << '\n';
	//check that all components are initialized to the correct value
	std::cout << "components " <<
		(std::all_of(components.begin(),components.end(),[=](double c){ return(c==initVal); })?
		 "are":"are not") << " correctly set\n";
	//check that memory is not aliased
	source2[0]=0;
	std::cout << "Memory aliasing: " << (dest2[0]==source2[0]) << '\n';
	std::cout << '\n';
}
void test()
{
   //Single unique_ptr
   reset_counters(); 
   sink1(source1());
   sink2(source2());
   sink3(source3());
   BOOST_TEST(A::count == 0);
   //Unbounded array unique_ptr
   reset_counters();
   sink1_unbounded_array(source1_unbounded_array());
   sink2_unbounded_array(source2_unbounded_array());
   sink3_unbounded_array(source3_unbounded_array());
   BOOST_TEST(A::count == 0);
   //Bbounded array unique_ptr
   reset_counters();
   sink1_bounded_array(source1_bounded_array());
   sink2_bounded_array(source2_bounded_array());
   sink3_bounded_array(source3_bounded_array());
   BOOST_TEST(A::count == 0);
}