How to know when and end of contiguous << operators has arrived

I have a function with the operator << overloaded
my_class & my_class::operator << (int value) { i++; return *this; }

So I can write :
my_class()<<1<<33<<44;
And I could do things when the destructor are called.

But I'f I have an instance, in example: i_myclass = new my_class();
*i_myclass<<1<<33<<44; does not fires any destructor.

So is there any way to know that there is not any more values ?
And I would not want to write :
*i_myclass<<1<<33<<44<<"stop";

Any idea ?
How about i_myclass->set( temporary_class() << 1 << 33 << 44 ); ?
mmm. My problem is I dont want to write a large code ....

I prefer *i_myclass<<1<<33<<44<<""; ( It is as works now) (I'd want to avoid the use of the final "").
So, I create my i_myclass one time for all the life of my program.

An adittional question :
Is there any way to write a function to receive an unknowed number of elements?
In example , I'd like to call myfunction (1,2,3,4,5,6,7) or myfunction (1,2,3).
myfunction ( <T> items... ) ??? Or something like this ? Or have I to write a lot of overloaded functions ?
Thanks





Last edited on
closed account (z05DSL3A)
An adittional question :
Is there any way to write a function to receive an unknowed number of elements?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <cassert>
#include <cstdarg>
using namespace std;

template < typename T >
T max(unsigned count, ...)
{
    assert(count > 0);
   
    va_list arguments;
    
    va_start(arguments, count);

    int result = va_arg(arguments, T);
    
    while(--count > 0)
    {
        T arg = va_arg(arguments, T);
        if (arg > result)
            result = arg;
    }
    
    va_end(arguments);

    return result;
}


int main() 
{
    int a(56), b(8), c(66),d(14);
    cout << max<int>(4 /*number of parameters passed */, a, b, c, d) <<endl;
    
    return 0;
}
thank you very much
closed account (z05DSL3A)
BTW it does not have to be a template function, I skimmed the last line of your question and miss read it.
Topic archived. No new replies allowed.