[ create a new paste ] login | about

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

xtofl - C++, pasted on May 1:
#include <cstdarg>
#include <iostream>

template< typename T >
void take_args( T sentinel, ... ) {
    va_list vars;
    va_start( vars, sentinel );

    // warning: the compiler may choose a type for vars that
    // does not allow this next cast!
    T* tvars = reinterpret_cast<T*>( vars );

    // here are variables of type T
    while( *tvars != sentinel ){
        std::cout << *tvars;
        ++tvars;
    }

    va_end( vars );
}

int main() {
    take_args<int>( 0, 1,2,3,4,5, 0 );
}


Output:
1
12345


Create a new paste based on this one


Comments: