Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

operator belongs_to

22 views
Skip to first unread message

Alex Vinokur

unread,
Mar 12, 2003, 4:45:06 AM3/12/03
to
Is it possible to define something like to operator belongs_to ?

For instance, I would like to know is some int-value val1 belongs to vector<int> vect1.

Instead of using find-algorithm I would prefer to use operator belongs_to.

--
=================================
Alex Vinokur
mailto:ale...@connect.to
http://www.simtel.net/pub/oth/19088.html
=================================


[ Send an empty e-mail to c++-...@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]

George van den Driessche

unread,
Mar 12, 2003, 4:37:20 PM3/12/03
to
How do you propose that "operator belongs_to" would be evaluated in this
case, other than as the result of evaluating
std::find( vect1.begin(), vect1.end(), val1 ) != vect1.end()
?

George


"Alex Vinokur" <ale...@bigfoot.com> wrote in message
news:b4mbue$21fr5e$1...@ID-79865.news.dfncis.de...

Ivan Vecerina

unread,
Mar 12, 2003, 5:09:47 PM3/12/03
to
"Alex Vinokur" <ale...@bigfoot.com> wrote in message
news:b4mbue$21fr5e$1...@ID-79865.news.dfncis.de...
| Is it possible to define something like to operator belongs_to ?
|
| For instance, I would like to know is some int-value val1 belongs to
vector<int> vect1.
|
| Instead of using find-algorithm I would prefer to use operator belongs_to.

Unless you need the elements of vect1 to be stored in a specific non-sorted
order,
you may want to consider using std::set or std::multiset instead of
std::vector.
These containers have a method for finding if an element is included
(and, for the multiset, how many copies of there are):
set1.count( elementToFind );

You cannot define a new operator, but creating a function such as
bool belongs_to( std::vector<int> const& v, int theValue );
is easy enough...

--
Ivan Vecerina, Dr. med. <> http://www.post1.com/~ivec
Soft Dev Manger, xitact <> http://www.xitact.com
Brainbench MVP for C++ <> http://www.brainbench.com

Sebastian Moleski

unread,
Mar 12, 2003, 5:26:19 PM3/12/03
to
"Alex Vinokur" <ale...@bigfoot.com> wrote in message
news:b4mbue$21fr5e$1...@ID-79865.news.dfncis.de...
> Is it possible to define something like to operator belongs_to ?
>
> For instance, I would like to know is some int-value val1 belongs to
vector<int> vect1.
>
> Instead of using find-algorithm I would prefer to use operator belongs_to.

No. You can't create new operators. It seems like you will have to keep
using the find functions. Alternatively, you could create a function that
fits your needs and that internally uses find to accomplish it's task, e.g.:

bool belongsTo(const std::vector& v) {
return std::find(v.begin(), v.end()) != v.end();
}

HTH,

sm

Alex Vinokur

unread,
Mar 13, 2003, 8:12:03 AM3/13/03
to

"Ivan Vecerina" <iv...@myrealbox.com> wrote in message news:3e6f42e0$1...@news.swissonline.ch...
[snip]

> You cannot define a new operator, but creating a function such as
> bool belongs_to( std::vector<int> const& v, int theValue );
> is easy enough...
>
Yes, I am using such a function.
I think in this case it is natural to use operator instead of function.

However, we should settle for using function.

Thanks,

=================================
Alex Vinokur
mailto:ale...@connect.to
http://www.simtel.net/pub/oth/19088.html
=================================

[ Send an empty e-mail to c++-...@netlab.cs.rpi.edu for info ]

Andrei Alexandrescu

unread,
Mar 13, 2003, 8:11:20 AM3/13/03
to
"Alex Vinokur" <ale...@bigfoot.com> wrote in message
news:b4mbue$21fr5e$1...@ID-79865.news.dfncis.de...
> Is it possible to define something like to operator belongs_to ?
>
> For instance, I would like to know is some int-value val1 belongs to
vector<int> vect1.
>
> Instead of using find-algorithm I would prefer to use operator belongs_to.

A while back I've been toying with a combination of macros and templates
that would allow you to write:

vector<int> v;
...
if (5 BELONGS_TO v) { ... }

The idea was to define BELONGS_TO like this:

#define BELONGS_TO *belongs_to*

and then define belongs_to as a global object with the appropriate *
operators.

The scaffolding is quite interesting, but overall I find the idea too whacky
to be acceptable. I kept it on hold just in case I'll run out of ideas for
my Generic<Programming> column, and hopefully I'll never need to use it :o).


Andrei

Tom Houlder

unread,
Mar 13, 2003, 7:00:07 PM3/13/03
to

"Alex Vinokur" <ale...@bigfoot.com> wrote in message
news:b4p0ga$22tv6r$1...@ID-79865.news.dfncis.de...

>
> "Ivan Vecerina" <iv...@myrealbox.com> wrote in message
news:3e6f42e0$1...@news.swissonline.ch...
> [snip]
> > You cannot define a new operator, but creating a function such as
> > bool belongs_to( std::vector<int> const& v, int theValue );
> > is easy enough...
> >
> Yes, I am using such a function.
> I think in this case it is natural to use operator instead of function.
>
> However, we should settle for using function.

If you prefer a member function to a free function you can define
a template class with additional utility member functions and derive
from std::vector via that class. Something along these lines:

template<class Cont>
class ContainerAddons : public Cont
{
// ...

bool
contains(const_reference x) const
{
return std::find(Cont::begin(), Cont::end(), x) != Cont::end();
}
};

template<class T>
class MyVector : public std::vector<T>
{
// ...
};

With usage:

MyVector<int> v;
bool isBelonged = v.contains(5);

Look in Stroustrup 3rd ed. for details.


Tom Houlder
thou...@houlder.net

Chic - C++ without hassles
http://www.houlder.net

Niklas Matthies

unread,
Mar 13, 2003, 7:19:30 PM3/13/03
to
On 2003-03-13 13:11, Andrei Alexandrescu <SeeWebsit...@moderncppdesign.com> wrote:
[...]

> A while back I've been toying with a combination of macros and templates
> that would allow you to write:
>
> vector<int> v;
> ...
> if (5 BELONGS_TO v) { ... }
>
> The idea was to define BELONGS_TO like this:
>
> #define BELONGS_TO *belongs_to*
>
> and then define belongs_to as a global object with the appropriate *
> operators.

Neat. I'd suggest

if (5 /belongs_to/ v) { ... }

or maybe

if (v |contains| 5) { ... }

or even

if (v <contains> 5) { ... }

which almost feels like infix invocation syntax built into the language.
No need for nasty macros.

-- Niklas Matthies

David B. Held

unread,
Mar 14, 2003, 5:53:30 AM3/14/03
to
"Andrei Alexandrescu" <SeeWebsit...@moderncppdesign.com> wrote in
message news:b4p8ou$22udjj$1...@ID-14036.news.dfncis.de...
> [...]

> A while back I've been toying with a combination of macros and
> templates that would allow you to write:
>
> vector<int> v;
> ...
> if (5 BELONGS_TO v) { ... }
>
> The idea was to define BELONGS_TO like this:
>
> #define BELONGS_TO *belongs_to*
>
> and then define belongs_to as a global object with the appropriate *
> operators.
> [...]

That looks vaguely like Delphi's "in" operator, which detects set
membership. It would be something like this:

if (5 in {1, 2, 3, 4, 5}) ...

Perhaps an overloadable "in" or "member_of" operator would be
useful? ;)

Dave

David Abrahams

unread,
Mar 14, 2003, 9:28:38 AM3/14/03
to
"David B. Held" <dh...@codelogicconsulting.com> writes:

> That looks vaguely like Delphi's "in" operator, which detects set
> membership. It would be something like this:
>
> if (5 in {1, 2, 3, 4, 5}) ...
>
> Perhaps an overloadable "in" or "member_of" operator would be
> useful? ;)

Of course you mean Python's "in" operator, don't you? <wink>

--
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Andrei Alexandrescu

unread,
Mar 14, 2003, 9:35:04 AM3/14/03
to
"Niklas Matthies" <comp.lang.c++.mod...@nmhq.net> wrote in
message news:slrnb71o4m.1sr3.comp.lang...@nmhq.net...

> On 2003-03-13 13:11, Andrei Alexandrescu
<SeeWebsit...@moderncppdesign.com> wrote:
> [...]
> > A while back I've been toying with a combination of macros and templates
> > that would allow you to write:
> >
> > vector<int> v;
> > ...
> > if (5 BELONGS_TO v) { ... }

[snip]

> if (v <contains> 5) { ... }
>
> which almost feels like infix invocation syntax built into the language.
> No need for nasty macros.

This looks sexy. (Will this post be robomoderated away? :o)). Does anyone
else think this is cool?

Andrei

Francis Glassborow

unread,
Mar 14, 2003, 9:44:58 AM3/14/03
to
In message <v72so2b...@corp.supernews.com>, David B. Held
<dh...@codelogicconsulting.com> writes

>That looks vaguely like Delphi's "in" operator, which detects set
>membership. It would be something like this:
>
>if (5 in {1, 2, 3, 4, 5}) ...
>
>Perhaps an overloadable "in" or "member_of" operator would be
>useful? ;)

I would like to see C++ support such a feature, in particular so that I
could write:

for(mytype 'in' container){...}

but 'in' certainly will not make it as a keyword.

--
ACCU Spring Conference 2003 April 2-5
The Conference you cannot afford to miss
Check the details: http://www.accuconference.co.uk/
Francis Glassborow ACCU

Daniel Frey

unread,
Mar 15, 2003, 4:03:43 AM3/15/03
to
Andrei Alexandrescu wrote:
>
> "Niklas Matthies" <comp.lang.c++.mod...@nmhq.net> wrote in
> message news:slrnb71o4m.1sr3.comp.lang...@nmhq.net...
> > On 2003-03-13 13:11, Andrei Alexandrescu
> <SeeWebsit...@moderncppdesign.com> wrote:
> > [...]
> > > A while back I've been toying with a combination of macros and templates
> > > that would allow you to write:
> > >
> > > vector<int> v;
> > > ...
> > > if (5 BELONGS_TO v) { ... }
>
> [snip]
>
> > if (v <contains> 5) { ... }
> >
> > which almost feels like infix invocation syntax built into the language.
> > No need for nasty macros.
>
> This looks sexy. (Will this post be robomoderated away? :o)). Does anyone
> else think this is cool?

Whether you call is '*contains*', '<contains>' or hide it in a macro
'CONTAINS' (or BELONGS_TO), it a clear case for a new column called
Pervert<Programming>. I don't think it's cool as it is a strange syntax
for "normal" C++ users and will create lots of confusion for no real
value (IMHO).

Regards, Daniel

PS: To robomoderate your post away, try to add a link for 'sexy':
http://www.moderncppdesign.com/pictures/showpic.html?/images/chicks.jpg

--
Daniel Frey

aixigo AG - financial training, research and technology
Schlo-Rahe-Strae 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: danie...@aixigo.de, web: http://www.aixigo.de

Tom Houlder

unread,
Mar 15, 2003, 4:05:12 AM3/15/03
to
"Andrei Alexandrescu" <SeeWebsit...@moderncppdesign.com> wrote in
message news:b4saov$22uck4$1...@ID-14036.news.dfncis.de...

> "Niklas Matthies" <comp.lang.c++.mod...@nmhq.net> wrote in
> message
news:slrnb71o4m.1sr3.comp.lang...@nmhq.net...
> > On 2003-03-13 13:11, Andrei Alexandrescu
> <SeeWebsit...@moderncppdesign.com> wrote:
> > [...]
> > > A while back I've been toying with a combination of macros and
templates
> > > that would allow you to write:
> > >
> > > vector<int> v;
> > > ...
> > > if (5 BELONGS_TO v) { ... }
>
> [snip]
>
> > if (v <contains> 5) { ... }
> >
> > which almost feels like infix invocation syntax built into the language.
> > No need for nasty macros.
>
> This looks sexy. (Will this post be robomoderated away? :o)). Does anyone
> else think this is cool?

No, it's awful ;-). It would lead to yet another meaning of the syntax
a<b>::c

which can be a qualified name (type or id):
a<b>::c
a perverse boolean expression:
a < b > ::c
or this new thing.

The lack of enough different parenthesis types has done enough harm to C++.


Tom Houlder
thou...@houlder.net

Chic - C++ without hassles
http://www.houlder.net

[ Send an empty e-mail to c++-...@netlab.cs.rpi.edu for info ]

John Potter

unread,
Mar 15, 2003, 4:16:14 AM3/15/03
to
On 14 Mar 2003 09:35:04 -0500, "Andrei Alexandrescu"
<SeeWebsit...@moderncppdesign.com> wrote:

> "Niklas Matthies" <comp.lang.c++.mod...@nmhq.net> wrote in
> message news:slrnb71o4m.1sr3.comp.lang...@nmhq.net...

> > if (v <contains> 5) { ... }


> >
> > which almost feels like infix invocation syntax built into the language.
> > No need for nasty macros.

> This looks sexy. Does anyone else think this is cool?

Cute may be a better word.

if (5 <in> v)

Less has been used for containment and also subset.

if (5 < v)

if (v > 5)

if (5 <= v)

These require only one simple overload.

John

Maciej Sobczak

unread,
Mar 15, 2003, 4:24:14 AM3/15/03
to
Hi,

"Francis Glassborow" <francis.g...@ntlworld.com> wrote in message
news:hwq5qED9...@robinton.demon.co.uk...

> I would like to see C++ support such a feature, in particular so that I
> could write:
>
> for(mytype 'in' container){...}

Would you impose some particular order of iteration?
Would you impose some specific interface of a container (a set of
requirements, like "implements begin() and end() that return interators")?
What about containers that do not have these members?
What about containers that do not have iterators at all?

It would be excessive mixing of the language and the library -- not
something I would like to see in C++.

> but 'in' certainly will not make it as a keyword.

nor any other name.

Personally, I do not like the idea to have Yet Another Fancy Way To Write
The Same Thing, especially when it comes to high-level issues like iterating
over a container.

Infix notation is not a big improvement over what we already have -- just a
syntactic sugar for template addicts. ;)

On the other hand (so I'm not that stiff), I like the piece:

>if (5 in {1, 2, 3, 4, 5}) ...

although switch/multiple-case does pretty well, too.

(BTW: those interested in Python please see the mess around PEP 308 -- this
is what happens when everybody tries to shove their ideas, of course "much"
better than all the others)

--
Maciej Sobczak
http://www.maciejsobczak.com/

Distributed programming lib for C, C++, Python & Tcl:
http://www.maciejsobczak.com/prog/yami/

Shannon Barber

unread,
Mar 15, 2003, 7:11:15 PM3/15/03
to
Francis Glassborow <francis.g...@ntlworld.com> wrote in message news:<hwq5qED9...@robinton.demon.co.uk>...
> In message <v72so2b...@corp.supernews.com>, David B. Held
> <dh...@codelogicconsulting.com> writes
> >That looks vaguely like Delphi's "in" operator, which detects set
> >membership. It would be something like this:
> >
> >if (5 in {1, 2, 3, 4, 5}) ...
> >
> >Perhaps an overloadable "in" or "member_of" operator would be
> >useful? ;)
>
> I would like to see C++ support such a feature, in particular so that I
> could write:
>
> for(mytype 'in' container){...}
>
> but 'in' certainly will not make it as a keyword.
>

What would it take to make C++ a functional programming language?
That is essentially where all such request point to.

Bill Weston

unread,
Mar 16, 2003, 6:00:12 PM3/16/03
to
"Alex Vinokur" <ale...@bigfoot.com> wrote in message news:<b4p0ga$22tv6r$1...@ID-79865.news.dfncis.de>...

> "Ivan Vecerina" <iv...@myrealbox.com> wrote in message news:3e6f42e0$1...@news.swissonline.ch...
> [snip]
> > You cannot define a new operator, but creating a function such as
> > bool belongs_to( std::vector<int> const& v, int theValue );
> > is easy enough...
> >
> Yes, I am using such a function.
> I think in this case it is natural to use operator instead of function.
>
which operator makes sense for membership?
< and >, >= and <= make sense for subsets:

bool operator<( Container_t const& lhs, Container_t const& rhs);

but for membership? Maybe <<= annd >>=. Not just << and >> i would
suggest, that looks too much like streams, and as if a value is
actually being transferred to or from the set. hmm &, &&, &= ? nah,
function name is good enough, surely?

Bill Weston.

James Slaughter

unread,
Mar 16, 2003, 6:50:28 PM3/16/03
to
"Niklas Matthies" <comp.lang.c++.mod...@nmhq.net> wrote in
message
news:slrnb71o4m.1sr3.comp.lang...@nmhq.net...
> Neat. I'd suggest
>
> if (5 /belongs_to/ v) { ... }
> or maybe
> if (v |contains| 5) { ... }
> or even
> if (v <contains> 5) { ... }
>
> which almost feels like infix invocation syntax built into the language.
> No need for nasty macros.

Actually, it would seem that the choice of operator has the effect of
defining a precedence and associativity, and therefore is probably best
hidden behind macros for consistency. It would also avoid needing to
occasionally put scope operators within their 'keywords' and the ensuing
fun created for people without the luxury of an implementation that allows
them to turn off digraphs.

Would I like to see an article about it? It's certainly an interesting and
twisted idea, yet somewhat less 'abusive' than things like Boost's own
lambda library. If people are prepared to release that into the wild, I
don't see what's wrong about a just-for-fun article exploring this and the
many other ways to contort the syntax, like overloading comma, etc. Just
for so long as the intent is clear :)

Regards,
James.

John Potter

unread,
Mar 17, 2003, 3:54:08 PM3/17/03
to
On 16 Mar 2003 18:00:12 -0500, w.we...@ntlworld.com (Bill Weston) wrote:

> which operator makes sense for membership?
> < and >, >= and <= make sense for subsets:

> bool operator<( Container_t const& lhs, Container_t const& rhs);

> but for membership?

The same makes as much sense. No need to do Container_t(1, x) < c.
An element is a set of size one and x < c should be clear.

John

James Kanze

unread,
Mar 22, 2003, 11:43:53 AM3/22/03
to
John Potter <jpo...@falcon.lhup.edu> writes:

|> On 16 Mar 2003 18:00:12 -0500, w.we...@ntlworld.com (Bill Weston) wrote:

|> > which operator makes sense for membership? < and >, >= and <=
|> > make sense for subsets:

|> > bool operator<( Container_t const& lhs, Container_t const& rhs);

|> > but for membership?

|> The same makes as much sense. No need to do Container_t(1, x) <
|> c. An element is a set of size one and x < c should be clear.

Using < for a non-transitive relationship is clear?

Actually, I'm tempted aussi. However, there is a trap involved:
something like std::set< Container_t > will result in undefined
behavior if you do.

--
James Kanze mailto:ka...@gabi-soft.fr
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
11 rue de Rambouillet, 78460 Chevreuse, France Tel. +33 1 41 89 80 93

John Potter

unread,
Mar 22, 2003, 4:49:27 PM3/22/03
to
On 22 Mar 2003 11:43:53 -0500, James Kanze <ka...@alex.gabi-soft.fr> wrote:

> John Potter <jpo...@falcon.lhup.edu> writes:
>
> |> On 16 Mar 2003 18:00:12 -0500, w.we...@ntlworld.com (Bill Weston) wrote:
>
> |> > which operator makes sense for membership? < and >, >= and <=
> |> > make sense for subsets:

> |> > bool operator<( Container_t const& lhs, Container_t const& rhs);

> |> > but for membership?

> |> The same makes as much sense. No need to do Container_t(1, x) <
> |> c. An element is a set of size one and x < c should be clear.

> Using < for a non-transitive relationship is clear?

Sure. 1 < 5 && 5 < {5} && ! (1 < {5}) is obvious. :)

> Actually, I'm tempted aussi. However, there is a trap involved:
> something like std::set< Container_t > will result in undefined
> behavior if you do.

The above problem was obvious, but this one escapes me. Please
spring the trap.

John

James Kanze

unread,
Mar 23, 2003, 3:31:50 PM3/23/03
to
John Potter <jpo...@falcon.lhup.edu> writes:

|> On 22 Mar 2003 11:43:53 -0500, James Kanze <ka...@alex.gabi-soft.fr> wrote:

|> > John Potter <jpo...@falcon.lhup.edu> writes:

|> > |> On 16 Mar 2003 18:00:12 -0500, w.we...@ntlworld.com (Bill Weston) wrote:

|> > |> > which operator makes sense for membership? < and >, >= and
|> > |> > <= make sense for subsets:

|> > |> > bool operator<( Container_t const& lhs, Container_t const&
|> > |> > rhs);

|> > |> > but for membership?

|> > |> The same makes as much sense. No need to do Container_t(1,
|> > |> x) < c. An element is a set of size one and x < c should be
|> > |> clear.

|> > Using < for a non-transitive relationship is clear?

|> Sure. 1 < 5 && 5 < {5} && ! (1 < {5}) is obvious. :)

|> > Actually, I'm tempted aussi. However, there is a trap involved:
|> > something like std::set< Container_t > will result in undefined
|> > behavior if you do.

|> The above problem was obvious, but this one escapes me. Please
|> spring the trap.

std::set< Container_t > uses std::less< Container_t > for it's
ordering relationship. std::less< Container_t > uses operator <, and
this operator doesn't define an ordering relationship in the sense of
the standard (that if !(a < b) and !(b < a), a and b are equal).

--
James Kanze mailto:ka...@gabi-soft.fr
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
11 rue de Rambouillet, 78460 Chevreuse, France Tel. +33 1 41 89 80 93

[ Send an empty e-mail to c++-...@netlab.cs.rpi.edu for info ]

John Potter

unread,
Mar 23, 2003, 6:12:19 PM3/23/03
to
On 23 Mar 2003 15:31:50 -0500, James Kanze <ka...@alex.gabi-soft.fr> wrote:

> John Potter <jpo...@falcon.lhup.edu> writes:
>
> |> On 22 Mar 2003 11:43:53 -0500, James Kanze <ka...@alex.gabi-soft.fr> wrote:

> |> > Actually, I'm tempted aussi. However, there is a trap involved:
> |> > something like std::set< Container_t > will result in undefined
> |> > behavior if you do.

> |> The above problem was obvious, but this one escapes me. Please
> |> spring the trap.

> std::set< Container_t > uses std::less< Container_t > for it's
> ordering relationship. std::less< Container_t > uses operator <, and
> this operator doesn't define an ordering relationship in the sense of
> the standard (that if !(a < b) and !(b < a), a and b are equal).

OK, I see what you are saying which does not involve using less for is
an element of. It is a problem for subset of because all of the
relational operators are defined for containers. If a subset operator<
or operator<= template were defined, it would be ignored in favor of
the predefined operator.

template <class T, class C> // is an element of
bool operator< (T const& e, C const& c) {
return find(c.begin(), c.end(), e) != c.end();
}
template <class T> // is an element of
bool operator< (T const& e, set<T> const& s) {
return s.find(e) != s.end();
}

There is no problem for set<set<int> > here because this does
not define set<int> < set<int> but set<int> < set<set<int> >.

John

Bill Weston

unread,
Mar 26, 2003, 5:14:32 PM3/26/03
to
John Potter <jpo...@falcon.lhup.edu> wrote in message news:<pju37vcijvn9nb2ko...@4ax.com>...

> On 14 Mar 2003 09:35:04 -0500, "Andrei Alexandrescu"
> <SeeWebsit...@moderncppdesign.com> wrote:
>
> > "Niklas Matthies" <comp.lang.c++.mod...@nmhq.net> wrote in
> > message news:slrnb71o4m.1sr3.comp.lang...@nmhq.net...
>
> > > if (v <contains> 5) { ... }
> > >
> > > which almost feels like infix invocation syntax built into the language.
> > > No need for nasty macros.
>
> > This looks sexy. Does anyone else think this is cool?
>
> Cute may be a better word.
>
> if (5 <in> v)

!Frivolity Warning!
Totally Frivolously.... you could use operator<-() for in...

if (5 <- v)...

because it looks a bit like the "is an element of" symbol!

[although what is wrong with if ( sits_inside(v,5) )..? ]

to get operator<-() so you can write

if (5 <- v)...

then you need operator unary minus on the v to produce a proxy
and operator < to take a thing and a proxy, and to work out whether
the 5 is in the v or not and return bool

the proxy wrapping v has a user defined type operator thing back to
the type of v, which returns -v, for when -v is used genuinely on its
own, if this makes sense.

cant do 'if ( v -> 5 )' though.

could do if ( v --> 5 ) and if( 5 <-- v ). How silly is this?
looks daft with spaces
if ( v -- > 5 )

>
> Less has been used for containment and also subset.
>
> if (5 < v)
>
> if (v > 5)
>
> if (5 <= v)
>
> These require only one simple overload.
>
> John
>

operator<=() looks the cutest for membership, i think... but its other
meaning(s) linger.


Bill

David B. Held

unread,
Mar 27, 2003, 7:51:59 AM3/27/03
to
"Bill Weston" <w.we...@ntlworld.com> wrote in message
news:d05617ba.03032...@posting.google.com...
> [...]

> !Frivolity Warning!
> Totally Frivolously.... you could use operator<-() for in...
>
> if (5 <- v)...
>
> because it looks a bit like the "is an element of" symbol!
> [...]

Well, if we want cute & frivolous, let's create an operator E. ;)

if (5 E v);

Of course, that can both be confused for scientific notation and
electron volts. ;> The right answer, of course, is to extend C++'s
character set to include Unicode, and include the member-of
symbol as an overloadable operator. ;>

Dave

Francis Glassborow

unread,
Mar 27, 2003, 7:51:35 PM3/27/03
to
In message <v853r7m...@corp.supernews.com>, David B. Held
<dh...@codelogicconsulting.com> writes

>"Bill Weston" <w.we...@ntlworld.com> wrote in message
>news:d05617ba.03032...@posting.google.com...
> > [...]
> > !Frivolity Warning!
> > Totally Frivolously.... you could use operator<-() for in...
> >
> > if (5 <- v)...
> >
> > because it looks a bit like the "is an element of" symbol!
> > [...]
>
>Well, if we want cute & frivolous, let's create an operator E. ;)
>
>if (5 E v);
>
>Of course, that can both be confused for scientific notation and
>electron volts. ;> The right answer, of course, is to extend C++'s
>character set to include Unicode, and include the member-of
>symbol as an overloadable operator. ;>
>
Interesting, I have a paper in preparation suggesting a way that this
might be achieved without torpedoing the whole operator structure of
C++.

The idea relies on two things:

1) Providing a mechanism to generalise the extension of operator
functions to more than two parameters (I say generalise, because we
already have that for such special operators as operator new)

2) A mechanism for providing new operator symbols (possibly restricted
to those Unicode lists as operators)

So the proposal does not introduce any fundamentally new operators
(hence avoids issues with precedence, associativity and parsing --
largely) but does allow new symbols to be used for (possibly extended)
existing operators.


--
ACCU Spring Conference 2003 April 2-5
The Conference you cannot afford to miss
Check the details: http://www.accuconference.co.uk/
Francis Glassborow ACCU

0 new messages