Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) TestLazy_init

 

ToolTestLazy_init is a tool to test the Lazy_init class.

 

 

 

 

 

Downloads

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./ToolTestLazy_init/ToolTestLazy_init.pro

 

QT       += core
QT       -= gui
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app

INCLUDEPATH += ../../Classes/CppLazy_init

SOURCES += main.cpp

HEADERS += \
    ../../Classes/CppLazy_init/lazy_init.h

#
#
# Type of compile
#
#

CONFIG(release, debug|release) {
  DEFINES += NDEBUG NTRACE_BILDERBIKKEL
}

QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++

unix {
  QMAKE_CXXFLAGS += -Werror
}

#
#
# Boost
#
#

win32 {
  INCLUDEPATH += \
    ../../Libraries/boost_1_54_0
}

 

 

 

 

 

./ToolTestLazy_init/main.cpp

 

//---------------------------------------------------------------------------
/*
TestLazy_init. Tests the Lazy_init class.
Copyright (C) 2012 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTestLazy_init.htm
//---------------------------------------------------------------------------
#include <iostream>

#include "lazy_init.h"

struct W
{
  W() { std::cout << "W contructor\n"; }
  void f() const { std::cout << "I am W" << '\n'; }
};

struct X
{
  X(const int x) : m_x(x) { std::cout << "X contructor\n"; }
  void f() const { std::cout << m_x << '\n'; }
  const int m_x;
};

struct Y
{
  Y(const std::string& s) : m_s(s) { std::cout << "Y contructor\n"; }
  void f() const { std::cout << m_s << '\n'; }
  const std::string m_s;
};

struct Z
{
  Z(const std::string& s, const int i) : m_s(s), m_i(i) { std::cout << "Z contructor\n"; }
  void f() const { std::cout << m_s << m_i << '\n'; }
  const std::string m_s;
  const int m_i;
};

int main()
{
  std::cout << "Lazy construction\n";
  ribi::LazyInit0<W> w;
  ribi::LazyInit1<X,int> x(314);
  ribi::LazyInit1<Y,std::string> y("Hello World");
  ribi::LazyInit2<Z,std::string,int> z("Hell",0);
  std::cout << "Calling objects\n";
  z.Get().f();
  y.Get().f();
  x.Get().f();
  w.Get().f();
}

/* Screen output:

Lazy construction
Calling objects
Z contructor
Hell0
Y contructor
Hello World
X contructor
314
W contructor
I am W
Press <RETURN> to close this window...

*/

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml