Skip to content

Latest commit

 

History

History
110 lines (61 loc) · 4.98 KB

File metadata and controls

110 lines (61 loc) · 4.98 KB

 

 

 

 

 

 

C++11STLQt CreatorLubuntu

 

std::function example 1: global functions is a std::function example.

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

  • STL STL: GNU ISO C++ Library, version 4.9.2

 

 

 

 

 

Qt project file: ./CppStdFunctionExample1/CppStdFunctionExample1.pro

 


TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt SOURCES += main.cpp # # # Type of compile # # CONFIG(debug, debug|release) {   message(Debug mode) } CONFIG(release, debug|release) {   message(Release mode)   #Remove all asserts and TRACE   DEFINES += NDEBUG NTRACE_BILDERBIKKEL } # # # Platform specific # # # # # Compiler flags # # QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra unix {   QMAKE_CXXFLAGS += -Werror } # # # Boost # # unix {   message(Unix: Boost already in include path) } win32 {   message(Windows: add Boost to include path)   INCLUDEPATH += \     E:/Projects/Libraries/boost_1_54_0 }

 

 

 

 

 

./CppStdFunctionExample1/main.cpp

 


#include <algorithm> #include <functional> #include <iostream> #include <vector> int f1(const int i) { return i + 1; } int f2(const int i) { return i + 2; } int f3(const int i) { return i + 3; } int main() {   std::vector<std::function<int(const int)> > v;   v.push_back(f1);   v.push_back(f2);   v.push_back(f3);   std::random_shuffle(v.begin(),v.end());   int x = 0;   for(const std::function<int(const int)>& f: v)   {     x = f(x);     std::cout << x << '\n';   } } /* Possible screen output: 1 4 6 Press <RETURN> to close this window... */