Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
replace_copy_if-30-Seconds-of-C++
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
#include <iostream> #include <vector> #include <algorithm> int main() { auto isOdd = [](int i) { return ((i%2) == 1); }; std::vector<int> origin {1, 2, 3, 4, 5}; std::vector<int> destination; // Copy elements to destination replacing elements that return true for isOdd by 0 std::replace_copy_if(origin.begin(), //first origin.end(), //last std::back_inserter(destination), //d_first isOdd, //condition 0 //new_value ); // origin is still {1, 2, 3, 4, 5} for (auto value : origin) { std::cout << value << " "; } std::cout << std::endl; // destination is {0, 2, 0, 4, 0} for (auto value : destination) { std::cout << value << " "; } std::cout << std::endl; }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.93 sec, absolute running time: 0.08 sec, cpu time: 0.02 sec, memory peak: 3 Mb, absolute service time: 1,03 sec
edit mode
|
history
|
discussion
1 2 3 4 5 0 2 0 4 0