Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) TemplateFunctionExample5

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppTemplateFunctionExample5/CppTemplateFunctionExample5.pro

 

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp

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

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

unix {
  QMAKE_CXXFLAGS += -Werror
}

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

 

 

 

 

 

./CppTemplateFunctionExample5/main.cpp

 

#include <cstdlib>
#include <iostream>
#include <type_traits>

template <class T> void Cout(const T* t)
{
  std::cout << (*t) << '\n';
}

template <class T> void Cout(const T& t )
{
  std::cout << (t) << '\n';
}

template <class Container> void Cout(const Container& v)
{
  //How to get this to work?
  for (const Container::value_type t: v)
  {
    Cout<const Container::value_type>(t);
  }
}


int main()
{
  const int x = 42;
  const double * const p  = new double(123.456);
  const std::vector<int *> v { new int(1), new int(2), new int(3) };

  Cout(x);
  Cout(p);

  Cout(v); //How to get this to work?
}

/* Screen output:

*/

 

 

 

 

 

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