Showing posts with label template. Show all posts
Showing posts with label template. Show all posts

2010-05-21

C++: Initializing containers with compile time list of data

template <typename T, size_t size>
void FillSet(std::set<T>& target, const T (&list)[size])
{
    for(size_t i=0; i<size; ++i)
        target.insert(list[i]);
}
Usage example:
int startkit[] = {10,2,8,4,3,1};
std::set<int> numbers;
FillSet(numbers,startkit);

2010-04-13

Etióp szorzás / Ethiopian Multiplication

@ Rosetta code
http://rosettacode.org/wiki/Ethiopian_Multiplication

Különösen finom / Extraordinarily tasty:
C++ template implementation
http://rosettacode.org/wiki/Ethiopian_Multiplication#C.2B.2B