Topic: How to describe any type of parameter passed to function
Author: grizlyk1@yandex.ru ("Grizlyk")
Date: Thu, 15 Feb 2007 05:48:56 GMT Raw View
Hello.
I have a question about: "how C++ could declare the way, how parameter will
be passed to function".
I have tryed to describe all possible situations below. Who can give me any
ideas about it?
A.
We have four different kinds of parameters
a) copyable parameter passed by reference
b) moveable parameter passed by reference
c) copyable parameter passed by value
d) moveable parameter passed by value
and we must have
1. what syntax must be used to declare each type of parameter of function
2. what kind of ctor or operator must be used to create the concrete type of
parameter during function call
B.
copyable and moveable.
- copyable - we can create new copy of object from source with the help of
method copy().
- moveable - we can pass ownership of unique internal state from source
object to destanation object with the help of method move() (state of source
object after moving became incorrect)
C.
syntax and operators
// ***
a) copyable parameter passed by reference
The declaration sign "&" say that "data" will be created as reference of src
1. foo(const T& data)
foo(T& data)
2. T::operator??? what kind of operator makes references of copyable?
// foo::data==src
{const T src; foo(src);}
// foo::data==src
{ T src; foo(src);}
Can we declare the operator as private to deny object passed to function by
reference?
// ***
b) moveable parameter passed by reference
The declaration sign "&" say that "data" will be created as reference of src
1. foo(const T& data)
foo(T& data)
2. T::operator??? what kind of operator makes references of moveable?
//foo::data==src
{const T src; foo(src);}
//foo::data==src
{ T src; foo(src);}
// ***
c) copyable parameter passed by value
No sign to declare copyable parameter passed by value - value by default,
say that "data" will be created by "copy" from "src"
1. foo(const T data)
foo(T data)
2. T::T(const T&)
/*T::T(T&)*/
// foo::data==T::T(const T& /*src*/)==src.copy()
{const T src; foo(src);}
// foo::data==T::T(const T& /*src*/)==src.copy()
{ T src; foo(src);}
Do we allow T::T(T&) to be used for "T src; foo(src);"? Is it good?
Is any class T, that have declared only T::T(T&), copyable?
// ***
d) moveable parameter passed by value
Let declaration sign "@" to declare moveable parameter passed by value, say
that "data" will be created by "move" from "src"
1. foo(const T@ data)
foo(T@ data)
2. T::T(const T@ data)
/*T::T(T@)*/
// foo::data==T::T(const T@ /*src*/)== src.move()
{const T src; foo(src);}
// foo::data==T::T(const T@ /*src*/)== src.move()
{ T src; foo(src);}
Do we allow T::T(T@) to be used for "T src; foo(src);"? Is it good?
Is any class T have declared only T::T(T@) moveable?
--
Maksim A. Polyanin
---
[ 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.comeaucomputing.com/csc/faq.html ]
Author: "Grizlyk" <grizlyk1@yandex.ru>
Date: Sun, 18 Feb 2007 09:59:58 CST Raw View
Hello.
I have some other good ideas to make my life better and work with C++
easyer, not only to include full support movable conception into C++.
I see, people here do not hurry up to like the idea. I agree, that it is not
easy for me to push the ideas into language, so the ideas (more then 30!)
will be published (beacause of they are already exist) to discuss and for
other purposes on the web page here: http://grizlyk1.narod.ru/cpp_new .
Note: The published proposals do not sorted by any rules. I will place all
of them one by one (it can take some time) maybe _without newsgroup
advertisements_. Reload the page sometimes to see news.
Your possible useful comments about already published ideas can change the
page.
Maybe any will use the page to include new properties into language.
--
Maksim A. Polyanin
---
[ 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.comeaucomputing.com/csc/faq.html ]