Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
C++ range-based loop control: skip last item
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
//clang 3.7.0 #include <iostream> #include <utility> template<typename T> struct trim_last { T& inner; friend auto begin( const trim_last& outer ) { using namespace std; return begin(outer.inner); } friend auto end( const trim_last& outer ) { using namespace std; auto b = begin(outer.inner), e = end(outer.inner); return e - (b != e); } }; template<typename T> trim_last<T> skip_last( T& inner ) { return { inner }; } int main() { int nums[] = { 1, 3, 5, 7 }; for( int val : skip_last(nums) ) { std::cout << val << ", "; } std::cout << std::end(nums)[-1] << "\n"; }
clang++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.32 sec, absolute running time: 0.14 sec, cpu time: 0 sec, memory peak: 3 Mb, absolute service time: 0,46 sec
fork mode
|
history
1, 3, 5, 7