Search Results

Search found 3 results on 1 pages for 'hippicoder'.

Page 1/1 | 1 

  • How to properly use references with variadic templates

    - by Hippicoder
    I have something like the following code: template<typename T1, typename T2, typename T3> void inc(T1& t1, T2& t2, T3& t3) { ++t1; ++t2; ++t3; } template<typename T1, typename T2> void inc(T1& t1, T2& t2) { ++t1; ++t2; } template<typename T1> void inc(T1& t1) { ++t1; } I'd like to reimplement it using the proposed variadic templates from the upcoming standard. However all the examples I've seen so far online seem to be printf like examples, the difference here seems to be the use of references. I've come up with the following: template<typename T> void inc(T&& t) { ++t; } template<typename T,typename ... Args> void inc(T&& t, Args&& ... args) { ++t inc(args...); } What I'd like to know is: Should I be using r-values instead of references? Possible hints or clues as to how to accomplish what I want correctly. What guarantees does the new proposed standard provide wrt the issue of the recursive function calls, is there some indication that the above variadic version will be as optimal as the original? (should I add inline or some-such?)

    Read the article

  • Is there a standard Cyclic Iterator in C++

    - by Hippicoder
    Based on the following question: Check if one string is a rotation of other string I was thinking of making a cyclic iterator type that takes a range, and would be able to solve the above problem like so: std::string s1 = "abc" ; std::string s2 = "bca" ; std::size_t n = 2; // number of cycles cyclic_iterator it(s2.begin(),s2.end(),n); cyclic_iterator end; if (std::search(it, end, s1.begin(),s1.end()) != end) { std::cout << "s1 is a rotation of s2" << std::endl; } My question, Is there already something like this available? I've check Boost and STL doesn't have one. I've got a simple hand-written one but would rather use an already made/tested implementation.

    Read the article

  • Programmatically create static arrays at compile time in C++

    - by Hippicoder
    One can define a static array at compile time as follows: const std::size_t size = 5; unsigned int list[size] = { 1, 2, 3, 4, 5 }; Question 1 - Is it possible by using various kinds of metaprogramming techniques to assign these values "programmatically" at compile time? Question 2 - Assuming all the values in the array are to be the same barr a few, is it possible to selectively assign values at compile time in a programmatic manner? eg: const std::size_t size = 7; unsigned int list[size] = { 0, 0, 2, 3, 0, 0, 0 }; Solutions using C++0x are welcome The array may be quite large, few hundred elements long The array for now will only consist of POD types It can also be assumed the size of the array will be known beforehand, in a static compile-time compliant manner. Solutions must be in C++ (no script or codegen based solutions)

    Read the article

1