[ create a new paste ] login | about

Link: http://codepad.org/Szh4jVxI    [ raw code | output | fork ]

C++, pasted on Jun 25:
#include <iostream>
#include <vector>
using namespace std;

vector<int> convert(int x) {
  vector<int> ret;
  do {
      ret.push_back(x & 1);
  }while(x>>=1);
  reverse(ret.begin(),ret.end());
  return ret;
}

auto print = [] (auto const& v) {
   for(const auto& e : v) { cout << e << " "; }
   cout << endl;

};

template <typename T>
int printStd(auto v) {
    for (auto i = v.begin(); i != v.end(); i++) {
        cout << *i << " ";    
    } 
    cout << endl;
    return 0;
}

int main() 
{
    int x = 98;
    vector<int> y = convert(x);
    print(y);    // Method 1 - Lambda
    printStd(y); // Method 2 - user defined function

    return 0;       
}


Output:
1
2
Line 14: error: ISO C++ forbids declaration of 'print' with no type
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: