Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) Array_merge

 

STL

 

Array_merge is an array example.

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppArray_merge/CppArray_merge.pro

 

include(../../ConsoleApplication.pri) #Or use the code below
# QT += core
# QT += gui
# greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
# CONFIG   += console
# CONFIG   -= app_bundle
# TEMPLATE = app
# CONFIG(release, debug|release) {
#   DEFINES += NDEBUG NTRACE_BILDERBIKKEL
# }
# QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++
# unix {
#   QMAKE_CXXFLAGS += -Werror
# }

SOURCES += main.cpp

 

 

 

 

 

./CppArray_merge/main.cpp

 

#include <algorithm>
#include <cassert>
#include <vector>

///Modeled after the PHP function array_merge
template <class T>
const std::vector<T> array_merge(
  const std::vector<T>& v,
  const std::vector<T>& w)
{
  std::vector<T> x { v };
  std::copy(w.begin(),w.end(),std::back_inserter(x));
  return x;
}

int main()
{
  const std::vector<int> a { 0,1,2 };
  const std::vector<int> b { 0,2,4,6 };

  //Concatenate the arrays
  const std::vector<int> expected { 0,1,2,0,2,4,6 };

  //Find the merged set, raw
  const std::vector<int> result = array_merge(a,b);
  assert(result == expected);
}

 

 

 

 

 

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