Search code examples
c++operator-overloadingstandards

Is it possible to overload operator "..." in C++?


#include <iostream>
#include <vector>

using namespace std;

//
// Below is what I want but not legal in current C++!
//
vector<int> operator ...(int first, int last)
{
    vector<int> coll;
    for (int i = first; i <= last; ++i)
    {
        coll.push_back(i);
    }

    return coll;
}

int main()
{
    for (auto i : 1...4)
    {
        cout << i << endl;
    }
}

I want to generate an integer sequence by using syntax 1...100, 7...13, 2...200 and the like.

I want to overload ... in C++.

Is it possible?


Solution

  • Is it possible?

    No, it isn't possible.

    ... isn't an operator but a placeholder for variadic arguments.