Ejemplo n.º 1
0
auto f1(int n) {
    std::cout << "===== f1 start =====" << std::endl;
    if (n < 1) {
        ////////////////////////////////////////
        // version 1, NRVO
        //
        // auto tmp = MyClass(n);
        //
        ////////////////////////////////////////
        // version 2, NRVO for const local

        const  auto tmp = MyClass(n);

        ////////////////////////////////////////
        std::cout << "===== f1 end   =====" << std::endl;
        return tmp;
    } else {
        ////////////////////////////////////////
        // version 1, default ctor
        //
        // auto tmp = MyClass(n) + f1(n-1);   // will call "default ctor" here, and "dtor" later
        //
        ////////////////////////////////////////
        // version 2, NRVO

        auto tmp = MyClass(n);
        tmp += f1(n-1);

        ////////////////////////////////////////
        std::cout << "===== f1 end   =====" << std::endl;
        return tmp;
    }
}
Ejemplo n.º 2
0
int main(int argc, char* argv[])
{
  MyClass m;
  m.DoThing();

  MyClass().DoThing();

  const MyClass& crm = m;
  crm.DoThing();

  auto returnMyClass = []() -> const MyClass
  {
    return MyClass();
  };
  returnMyClass().DoThing();
}
Ejemplo n.º 3
0
void tst_QMap::clear()
{
    {
	MyMap map;
	map.clear();
	QVERIFY( map.isEmpty() );
	map.insert( "key", MyClass( "value" ) );
	map.clear();
	QVERIFY( map.isEmpty() );
	map.insert( "key0", MyClass( "value0" ) );
	map.insert( "key0", MyClass( "value1" ) );
	map.insert( "key1", MyClass( "value2" ) );
	map.clear();
	QVERIFY( map.isEmpty() );
    }
    QCOMPARE( MyClass::count, int(0) );
}
Ejemplo n.º 4
0
void object_global() {
  int aux = 0;
	for (int k = 0; k < repetetions; ++k) {	
    global_obj = MyClass(true,12345);
		if (global_obj.a) {
			aux += 1;
    }
  }
}
Ejemplo n.º 5
0
void object_outside_function(MyClass obj) {
  int aux = 0;
	for (int k = 0; k < repetetions; ++k) {	
    obj = MyClass(true,12345);
		if (obj.a) {
			aux += 1;
    }
  }
}
Ejemplo n.º 6
0
void tst_QExplicitlySharedDataPointer::pointerOperatorOnMutable() const
{
    /* Pointer itself is const. */
    {
        const QExplicitlySharedDataPointer<MyClass> pointer(new MyClass());
        pointer->notMutating();
        pointer->mutating();
        *pointer = MyClass();
    }

    /* Pointer itself is mutable. */
    {
        const QExplicitlySharedDataPointer<MyClass> pointer(new MyClass());
        pointer->notMutating();
        pointer->mutating();
        *pointer = MyClass();
    }
}
Ejemplo n.º 7
0
int main()
{
    const MyClass myConstClass = MyClass();
    myConstClass.getI();
    
    MyClass myNonConstClass;
    myNonConstClass.getI();
    
    return 0;
}
Ejemplo n.º 8
0
int main()
{
    const std::vector<std::any> anyVec{true, 2017, std::string("test"), 3.14, MyClass()};

    std::cout << std::any_cast<bool>(anyVec[0]) << std::endl;  // true
    std::cout << std::any_cast<int>(anyVec[1]) << std::endl;  // 2017

    std::cout << anyVec[0].type().name() << std::endl;  // b
    std::cout << anyVec[1].type().name() << std::endl;  // i
}
Ejemplo n.º 9
0
int main(int argc, char *argv[]){

  // instancia na stack
  MyClass myc_stack = MyClass();

  // instancia na heap
  MyClass *myc_heap = new MyClass();
  delete myc_heap;

  return 0;
}
Ejemplo n.º 10
0
int main()
{
  std::set<MyClass,std::function<bool(MyClass,MyClass)>> s(
    [](const MyClass& lhs, const MyClass& rhs)
    {
      return lhs.m_x < rhs.m_x;
    }
  );
  //Insert ordered by s
  s.insert(MyClass("five",5));
  s.insert(MyClass("four",4));
  s.insert(MyClass("one",1));
  s.insert(MyClass("six",6));
  s.insert(MyClass("three",3));
  s.insert(MyClass("two",2));
  //Show that the set orders by MyClass their x
  std::copy(s.begin(),s.end(),std::ostream_iterator<MyClass>(std::cout,"\n"));
}
Ejemplo n.º 11
0
int main(){
	printf("Hello there dolly\n");

	MyClass me;
	MyClass you;
	printf("My age is %d\n",me.getAge());
	you = me + you;
	printf("The new age is %d\n", you.getAge());

	MyClass oldDude(100);
	MyClass youngDude(13);
	MyClass olderDude = oldDude + youngDude;
	printf("The older dude age is %d\n", olderDude.getAge());
	me = MyClass(113);
	bool res = (olderDude == me);
	printf("The two are equal = %d\n", res);
	
	MyClass* classp = new MyClass(500);

	printf("class pointer age is %d\n",classp->getAge());
	printf("the addr of it is %p\n", classp);
	delete classp;
	return 0;	
}
	MyClass getClass()
	{
		return MyClass();
	}
Ejemplo n.º 13
0
int main()
{
	MyClass objectA;
	MyClass objectB(MyClass());
	return 0;
}
Ejemplo n.º 14
0
int main()
{
	MyClass mc_a;
	MyClass mc_b = MyClass();
}
Ejemplo n.º 15
0
void tst_QMap::count()
{
    {
	MyMap map;
	MyMap map2( map );
	QCOMPARE( map.count(), 0 );
	QCOMPARE( map2.count(), 0 );
	QCOMPARE( MyClass::count, int(0) );
	// detach
	map2["Hallo"] = MyClass( "Fritz" );
	QCOMPARE( map.count(), 0 );
        QCOMPARE( map2.count(), 1 );
#ifndef Q_CC_SUN
	QCOMPARE( MyClass::count, 1 );
#endif
    }
    QCOMPARE( MyClass::count, int(0) );

    {
	typedef QMap<QString, MyClass> Map;
	Map map;
	QCOMPARE( map.count(), 0);
	map.insert( "Torben", MyClass("Weis") );
	QCOMPARE( map.count(), 1 );
	map.insert( "Claudia", MyClass("Sorg") );
	QCOMPARE( map.count(), 2 );
	map.insert( "Lars", MyClass("Linzbach") );
	map.insert( "Matthias", MyClass("Ettrich") );
	map.insert( "Sue", MyClass("Paludo") );
	map.insert( "Eirik", MyClass("Eng") );
	map.insert( "Haavard", MyClass("Nord") );
	map.insert( "Arnt", MyClass("Gulbrandsen") );
	map.insert( "Paul", MyClass("Tvete") );
	QCOMPARE( map.count(), 9 );
	map.insert( "Paul", MyClass("Tvete 1") );
	map.insert( "Paul", MyClass("Tvete 2") );
	map.insert( "Paul", MyClass("Tvete 3") );
	map.insert( "Paul", MyClass("Tvete 4") );
	map.insert( "Paul", MyClass("Tvete 5") );
	map.insert( "Paul", MyClass("Tvete 6") );

	QCOMPARE( map.count(), 9 );
#ifndef Q_CC_SUN
	QCOMPARE( MyClass::count, 9 );
#endif

	Map map2( map );
	QVERIFY( map2.count() == 9 );
#ifndef Q_CC_SUN
	QCOMPARE( MyClass::count, 9 );
#endif

	map2.insert( "Kay", MyClass("Roemer") );
	QVERIFY( map2.count() == 10 );
	QVERIFY( map.count() == 9 );
#ifndef Q_CC_SUN
	QCOMPARE( MyClass::count, 19 );
#endif

	map2 = map;
	QVERIFY( map.count() == 9 );
	QVERIFY( map2.count() == 9 );
#ifndef Q_CC_SUN
	QCOMPARE( MyClass::count, 9 );
#endif

	map2.insert( "Kay", MyClass("Roemer") );
	QVERIFY( map2.count() == 10 );
#ifndef Q_CC_SUN
	QCOMPARE( MyClass::count, 19 );
#endif

	map2.clear();
	QVERIFY( map.count() == 9 );
	QVERIFY( map2.count() == 0 );
#ifndef Q_CC_SUN
	QCOMPARE( MyClass::count, 9 );
#endif

	map2 = map;
	QVERIFY( map.count() == 9 );
	QVERIFY( map2.count() == 9 );
#ifndef Q_CC_SUN
	QCOMPARE( MyClass::count, 9 );
#endif

	map2.clear();
	QVERIFY( map.count() == 9 );
	QVERIFY( map2.count() == 0 );
#ifndef Q_CC_SUN
	QCOMPARE( MyClass::count, 9 );
#endif

	map.remove( "Lars" );
	QVERIFY( map.count() == 8 );
	QVERIFY( map2.count() == 0 );
#ifndef Q_CC_SUN
	QCOMPARE( MyClass::count, 8 );
#endif

	map.remove( "Mist" );
	QVERIFY( map.count() == 8 );
	QVERIFY( map2.count() == 0 );
#ifndef Q_CC_SUN
	QCOMPARE( MyClass::count, 8 );
#endif
    }
    QVERIFY( MyClass::count == 0 );

    {
	typedef QMap<QString,MyClass> Map;
	Map map;
	map["Torben"] = MyClass("Weis");
#ifndef Q_CC_SUN
	QVERIFY( MyClass::count == 1 );
#endif
	QVERIFY( map.count() == 1 );

	(void)map["Torben"].str;
	(void)map["Lars"].str;
#ifndef Q_CC_SUN
	QVERIFY( MyClass::count == 2 );
#endif
	QVERIFY( map.count() == 2 );

	const Map& cmap = map;
	(void)cmap["Depp"].str;
#ifndef Q_CC_SUN
	QVERIFY( MyClass::count == 2 );
#endif
	QVERIFY( map.count() == 2 );
	QVERIFY( cmap.count() == 2 );
    }
    QCOMPARE( MyClass::count, 0 );
    {
	for ( int i = 0; i < 100; ++i )
	{
	    QMap<int, MyClass> map;
	    for (int j = 0; j < i; ++j)
		map.insert(j, MyClass(QString::number(j)));
	}
	QCOMPARE( MyClass::count, 0 );
    }
    QCOMPARE( MyClass::count, 0 );
}
Ejemplo n.º 16
0
void wxAnyTestCase::wxVariantConversions()
{
#if wxUSE_VARIANT
    //
    // Test various conversions to and from wxVariant
    //
    bool res;

    // Prepare wxVariants
    wxVariant vLong(123L);
    wxVariant vString("ABC");
    wxVariant vDouble(TEST_FLOAT_CONST);
    wxVariant vBool((bool)true);
    wxVariant vChar('A');
#ifdef wxLongLong_t
    wxVariant vLongLong(wxLongLong(wxLL(0xAABBBBCCCC)));
    wxVariant vULongLong(wxULongLong(wxULL(123456)));
#endif
    wxArrayString arrstr;
    arrstr.push_back("test string");
    wxVariant vArrayString(arrstr);
    wxVariant vDateTime(m_testDateTime);
    wxVariant vVoidPtr(dummyVoidPointer);
    wxVariant vCustomType(new wxMyVariantData(MyClass(101)));
    wxVariant vList;

    vList.NullList();
    vList.Append(15);
    vList.Append("abc");

    // Convert to wxAnys, and then back to wxVariants
    wxVariant variant;

    wxAny any(vLong);
    CPPUNIT_ASSERT(any == 123L);
    res = any.GetAs(&variant);
    CPPUNIT_ASSERT(res);
    CPPUNIT_ASSERT(variant == 123L);

    // Make sure integer variant has correct type information
    CPPUNIT_ASSERT(variant.GetLong() == 123);
    CPPUNIT_ASSERT(variant.GetType() == "long");

    // Unsigned long wxAny should convert to "ulonglong" wxVariant
    any = 1000UL;
    res = any.GetAs(&variant);
    CPPUNIT_ASSERT(res);
    CPPUNIT_ASSERT(variant.GetType() == "ulonglong");
    CPPUNIT_ASSERT(variant.GetLong() == 1000);

    any = vString;
    CPPUNIT_ASSERT(any == "ABC");
    res = any.GetAs(&variant);
    CPPUNIT_ASSERT(res);
    CPPUNIT_ASSERT(variant.GetString() == "ABC");

    // Must be able to build string wxVariant from wxAny built from
    // string literal
    any = "ABC";
    res = any.GetAs(&variant);
    CPPUNIT_ASSERT(res);
    CPPUNIT_ASSERT(variant.GetType() == "string");
    CPPUNIT_ASSERT(variant.GetString() == "ABC");
    any = L"ABC";
    res = any.GetAs(&variant);
    CPPUNIT_ASSERT(res);
    CPPUNIT_ASSERT(variant.GetType() == "string");
#if wxUSE_UNICODE
    CPPUNIT_ASSERT(variant.GetString() == L"ABC");
#endif

    any = vDouble;
    double d = wxANY_AS(any, double);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(d, TEST_FLOAT_CONST, FEQ_DELTA);
    res = any.GetAs(&variant);
    CPPUNIT_ASSERT(res);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(variant.GetDouble(),
                                 TEST_FLOAT_CONST,
                                 FEQ_DELTA);

    any = vBool;
    CPPUNIT_ASSERT(wxANY_AS(any, bool) == true);
    res = any.GetAs(&variant);
    CPPUNIT_ASSERT(res);
    CPPUNIT_ASSERT(variant.GetBool() == true);

    any = wxAny(vChar);
    //CPPUNIT_ASSERT(wxANY_AS(any, wxUniChar) == 'A');
    res = any.GetAs(&variant);
    CPPUNIT_ASSERT(res);
    CPPUNIT_ASSERT(variant.GetChar() == 'A');

#ifdef wxLongLong_t
    any = wxAny(vLongLong);
    CPPUNIT_ASSERT(any == wxLL(0xAABBBBCCCC));
    res = any.GetAs(&variant);
    CPPUNIT_ASSERT(res);
    CPPUNIT_ASSERT(variant.GetType() == "longlong");
    CPPUNIT_ASSERT(variant.GetLongLong() == wxLongLong(wxLL(0xAABBBBCCCC)));

#if LONG_MAX == wxINT64_MAX
    // As a sanity check, test that wxVariant of type 'long' converts
    // seamlessly to 'longlong' (on some 64-bit systems)
    any = 0xAABBBBCCCCL;
    res = any.GetAs(&variant);
    CPPUNIT_ASSERT(variant.GetLongLong() == wxLongLong(wxLL(0xAABBBBCCCC)));
#endif

    any = wxAny(vULongLong);
    CPPUNIT_ASSERT(any == wxLL(123456));
    res = any.GetAs(&variant);
    CPPUNIT_ASSERT(res);
    CPPUNIT_ASSERT(variant.GetType() == "ulonglong");
    CPPUNIT_ASSERT(variant.GetULongLong() == wxULongLong(wxULL(123456)));
#endif

    // Cannot test equality for the rest, just test that they convert
    // back correctly.
    any = wxAny(vArrayString);
    res = any.GetAs(&variant);
    CPPUNIT_ASSERT(res);
    wxArrayString arrstr2 = variant.GetArrayString();
    CPPUNIT_ASSERT(arrstr2 == arrstr);

    any = m_testDateTime;
    CPPUNIT_ASSERT(wxANY_AS(any, wxDateTime) == m_testDateTime);
    any = wxAny(vDateTime);
    CPPUNIT_ASSERT(wxANY_AS(any, wxDateTime) == m_testDateTime);
    res = any.GetAs(&variant);
    CPPUNIT_ASSERT(res);
    CPPUNIT_ASSERT(variant == m_testDateTime);

    any = wxAny(vVoidPtr);
    res = any.GetAs(&variant);
    CPPUNIT_ASSERT(res);
    CPPUNIT_ASSERT(variant.GetVoidPtr() == dummyVoidPointer);

    any = wxAny(vList);
    CPPUNIT_ASSERT(wxANY_CHECK_TYPE(any, wxAnyList));
    wxAnyList anyList = wxANY_AS(any, wxAnyList);
    CPPUNIT_ASSERT(anyList.GetCount() == 2);
    CPPUNIT_ASSERT(wxANY_AS((*anyList[0]), int) == 15);
    CPPUNIT_ASSERT(wxANY_AS((*anyList[1]), wxString) == "abc");
    res = any.GetAs(&variant);
    CPPUNIT_ASSERT(res);
    CPPUNIT_ASSERT(variant.GetType() == "list");
    CPPUNIT_ASSERT(variant.GetCount() == 2);
    CPPUNIT_ASSERT(variant[0].GetLong() == 15);
    CPPUNIT_ASSERT(variant[1].GetString() == "abc");

    any = wxAny(vCustomType);
    CPPUNIT_ASSERT(wxANY_CHECK_TYPE(any, wxVariantData*));
    res = any.GetAs(&variant);
    CPPUNIT_ASSERT(res);
    CPPUNIT_ASSERT(variant.GetType() == "MyClass");

#endif // wxUSE_VARIANT
}
Ejemplo n.º 17
0
MyClass operator+(MyClass& p1, MyClass& p2){
	return MyClass(p1.age + p2.age);
}
int add2(int x) {
  return MyClass().add<2>(x);
}
Ejemplo n.º 19
0
class MyClass {};
const MyClass myObject = MyClass();
int main() {return 0;}

Ejemplo n.º 20
0
int main()
{
  std::set<MyClass> container;
  container.insert(MyClass(3));
  return 0;
}
inline int add3(int x) {
  return MyClass().add<3>(x); // even though add<3> is ODR used, don't emit it since we don't codegen it
}
Ejemplo n.º 22
0
int main(int argc,char**argv){
    MyClass x=MyClass();
    x.public_method();
    //x.private_method();
}