Topic: HINT FOR NEW COMMA OPERATOR


Author: =?iso-8859-1?Q?Andr=E9_P=F6nitz?= <poenitz@htwm.de>
Date: Thu, 14 Dec 2000 14:08:27 GMT
Raw View
Sebastian Moleski <smoleski@surakware.com> wrote:
> You can do all of this with a structs today.

So how exactly would you implement the "decay to multiple arguments"
with today's structs?

Andre'

--=20
Andr=E9 P=F6nitz ........................................ poenitz@htwm.de

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: sirwillard@my-deja.com
Date: Thu, 14 Dec 2000 19:31:14 GMT
Raw View
In article <91abmd$f4k$1@narses.hrz.tu-chemnitz.de>,
  =?iso-8859-1?Q?Andr=E9_P=F6nitz?= <poenitz@htwm.de> wrote:
> Sebastian Moleski <smoleski@surakware.com> wrote:
> > You can do all of this with a structs today.
>
> So how exactly would you implement the "decay to multiple arguments"
> with today's structs?

With some fancy meta-programming.  Check out the Lambda Library in the
Boost file archives (http://www.boost.org for Boost home and
http://www.egroups.com for Boost eGroup including file archives).  It
includes a "tuple" template type that does just this.

--
William E. Kempf
Software Engineer, MS Windows Programmer


Sent via Deja.com
http://www.deja.com/

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: "Mycroft Holmes" <holmes@technologist.com>
Date: 2000/11/30
Raw View
for a future revision of C++, I'm suggesting a new comma operator as
follows:

(a,b)
returns an object whose leftmost bytes are "a" and the others are "b"
similar to:

template <class X, class Y>
pair<X,Y> operator,(X ogg1, Y ogg2)
{
    return make_pair(x,y);
}


where:

1) the new "," accepts any number of arguments (using brackets) and creates
a suitable composite class, such as:
{
    int a= 7;
    int b = 89;
    double c = 3.14;
    return (a,b,c);
}

2) you can declare a composite object using brackets, such as:

{
    (int,double,char) obj1;
}


3) the compiler ensires that the composite object is assembled from left to
right (read the following example)

{
   (int,double,char) obj1 = ( 3, -27.7, 'X' ) ;
  int* c = (int*) &obj1;

// now *c == 3

 double* d =  (char*)c+sizeof(int);    // now *d == -27.7        and so on
}


4) you may access individual objects using [], but you must use a constant
(at compilation time).
the compiler replaces the constant with a proper "shift", summing up all
lengths of preceding objects (using sizeof)


{
   (int,double,char) obj1 = ( 3, -27.7, 'X' ) ;

    char c = obj1[ 2 ];         // legal, compiled as    *(char*)
 (char*)&obj1 + sizeof(int)+ sizeof( double) )

    int i;
    obj1 [ i ] ;             // illegal

}


5) the composite object is automatically replaced by an array, whenever all
atoms are of the very same type. When this happens, you may use anything in
square brackets for addressing objects. example:

{
    (int,int,int) a = {3,4,5};        // complier replaces with a[3] =
{3,4,5}

    int i;
    a[i];        // allowed!

}




--
 The set of solutions is never empty.
 Two solutions together form a new problem.
-- Mycroft Holmes




---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: 2000/11/30
Raw View
In article <905t14$1jr8$1@stargate1.inet.it>, Mycroft Holmes
<holmes@technologist.com> writes
>for a future revision of C++, I'm suggesting a new comma operator as
>follows:

And exactly what do you propose we do with the current one (the sequence
operator)?


Francis Glassborow      Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 2000/12/01
Raw View
Mycroft Holmes wrote:
>
> for a future revision of C++, I'm suggesting a new comma operator as
> follows:
>
> (a,b)
> returns an object whose leftmost bytes are "a" and the others are "b"
> similar to:
>
> template <class X, class Y>
> pair<X,Y> operator,(X ogg1, Y ogg2)
> {
>     return make_pair(x,y);
> }

This would break the current comma operator.
However, since currently semicolons are not allowed inside expressions,
one could use (a;b;c) for it (with mandatory parentheses - otherwise the
semicolon is the statement separator).

Otherwise, it's IMHO a good idea.

>
> where:
>
> 1) the new "," accepts any number of arguments (using brackets) and creates
> a suitable composite class, such as:
> {
>     int a= 7;
>     int b = 89;
>     double c = 3.14;
>     return (a,b,c);
> }
>
> 2) you can declare a composite object using brackets, such as:
>
> {
>     (int,double,char) obj1;
> }
>
> 3) the compiler ensires that the composite object is assembled from left to
> right (read the following example)
>
> {
>    (int,double,char) obj1 = ( 3, -27.7, 'X' ) ;
>   int* c = (int*) &obj1;
>
> // now *c == 3
>
>  double* d =  (char*)c+sizeof(int);    // now *d == -27.7        and so on
> }

I don't understand this one.
Do you mean that the layout of (int, double, char) should be the same as
the layout of struct foo { int a; double b; char c; } ?

>
> 4) you may access individual objects using [], but you must use a constant
> (at compilation time).
> the compiler replaces the constant with a proper "shift", summing up all
> lengths of preceding objects (using sizeof)
>
> {
>    (int,double,char) obj1 = ( 3, -27.7, 'X' ) ;
>
>     char c = obj1[ 2 ];         // legal, compiled as    *(char*)
>  (char*)&obj1 + sizeof(int)+ sizeof( double) )
>
>     int i;
>     obj1 [ i ] ;             // illegal
>
> }
>
> 5) the composite object is automatically replaced by an array, whenever all
> atoms are of the very same type. When this happens, you may use anything in
> square brackets for addressing objects. example:
>
> {
>     (int,int,int) a = {3,4,5};        // complier replaces with a[3] =
> {3,4,5}
>
>     int i;
>     a[i];        // allowed!
>
> }

I don't like this one.

Another suggestion:

Automatic "decay" in argument lists:

Assuming that you have a function

  (int; double) foo();

and you have a function

  void bar(int, int, double);

but no function

  void bar(int, (int; double));

then it should be allowed to write

  bar(5, foo());

which shall be equivalent to

  {
    (int; double) tmp = foo();
    bar(5, tmp[1], tmp[2]);
  }

This would especially be useful for STL::

template<class FIter, class T>
 (FIter; FIter) my_equal_range(FIter first, FIter last, T const& value)
{
  std::pair<FIter, FIter> tmp = equal_range(first, last, value);
  return (tmp.first; tmp.second);
}

void foo()
{
  std::vector<int> v1, v2;
  // ...
  std::copy(my_equal_range(v1.begin(), v1.end(), 3),
std::back_inserter(v2));
  // ...
}

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: "Sebastian Moleski" <smoleski@surakware.com>
Date: 2000/12/02
Raw View
You can do all of this with a structs today.

sm


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]