Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #85508 > unrolled thread
| Started by | Cholo Lennon <chololennon@hotmail.com> |
|---|---|
| First post | 2022-07-20 18:42 -0300 |
| Last post | 2022-07-21 16:22 -0500 |
| Articles | 20 on this page of 24 — 7 participants |
Back to article view | Back to comp.lang.c++
Function overloading Cholo Lennon <chololennon@hotmail.com> - 2022-07-20 18:42 -0300
Re: Function overloading Lynn McGuire <lynnmcguire5@gmail.com> - 2022-07-20 19:22 -0500
Re: Function overloading Gawr Gura <gawrgura@mail.hololive.com> - 2022-07-20 22:44 -0700
Re: Function overloading Lynn McGuire <lynnmcguire5@gmail.com> - 2022-07-21 16:17 -0500
Re: Function overloading Cholo Lennon <chololennon@hotmail.com> - 2022-07-22 19:43 -0300
Re: Function overloading Lynn McGuire <lynnmcguire5@gmail.com> - 2022-07-22 18:38 -0500
Re: Function overloading Cholo Lennon <chololennon@hotmail.com> - 2022-07-24 01:24 -0300
Re: Function overloading Lynn McGuire <lynnmcguire5@gmail.com> - 2022-07-25 16:01 -0500
Re: Function overloading "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-07-26 00:05 +0200
Re: Function overloading Cholo Lennon <chololennon@hotmail.com> - 2022-07-30 18:04 -0300
Re: Function overloading Cholo Lennon <chololennon@hotmail.com> - 2022-07-30 18:03 -0300
Re: Function overloading Lynn McGuire <lynnmcguire5@gmail.com> - 2022-08-02 23:11 -0500
Re: Function overloading Bonita Montero <Bonita.Montero@gmail.com> - 2022-07-27 16:10 +0200
Re: Function overloading Bonita Montero <Bonita.Montero@gmail.com> - 2022-07-27 16:11 +0200
Re: Function overloading Bonita Montero <Bonita.Montero@gmail.com> - 2022-07-27 16:35 +0200
Re: Function overloading Bonita Montero <Bonita.Montero@gmail.com> - 2022-07-28 05:51 +0200
Re: Function overloading Lynn McGuire <lynnmcguire5@gmail.com> - 2022-07-27 14:54 -0500
Re: Function overloading Bonita Montero <Bonita.Montero@gmail.com> - 2022-07-28 05:43 +0200
Re: Function overloading Lynn McGuire <lynnmcguire5@gmail.com> - 2022-07-28 13:32 -0500
Re: Function overloading Lynn McGuire <lynnmcguire5@gmail.com> - 2022-07-27 15:01 -0500
Re: Function overloading Juha Nieminen <nospam@thanks.invalid> - 2022-07-21 05:45 +0000
Re: Function overloading Paavo Helde <eesnimi@osa.pri.ee> - 2022-07-21 09:04 +0300
Re: Function overloading Juha Nieminen <nospam@thanks.invalid> - 2022-07-21 07:16 +0000
Re: Function overloading Lynn McGuire <lynnmcguire5@gmail.com> - 2022-07-21 16:22 -0500
Page 1 of 2 [1] 2 Next page →
| From | Cholo Lennon <chololennon@hotmail.com> |
|---|---|
| Date | 2022-07-20 18:42 -0300 |
| Subject | Function overloading |
| Message-ID | <tb9ssj$s32$1@gioia.aioe.org> |
I am learning Rust. One missing C++/Java feature is function
overloading. One of the explanations of this decision is that "function
overloading is an anti-pattern", because, among other things, "it leads
to less readable and understandable code".
This surprised me because I consider it very useful. I really hate
having to code multiple functions with different names and almost the
same functionality. I suffered this in Python (its solution based in
decorators is not the best), and also in Typescript (its solution based
in several prototypes for a single function is really awful).
What is your opinion about the function overloading as an
"anti-pattern"? is it?
Disclaimer: "Overloading" where only types differ (but the number of
parameters are the same) is possible in Rust using generic traits,
something like the following:
struct MyPrinter;
trait Printer<T> {
fn print(&self, value: T);
}
impl Printer<i32> for MyPrinter {
fn print(&self, value: i32) {
println!("Value: {}", value);
}
}
impl Printer<&str> for MyPrinter {
fn print(&self, value: &str) {
println!("Value: {}", value);
}
}
fn main() {
let foo = MyPrinter;
foo.print(10);
foo.print("Hello");
}
--
Cholo Lennon
Bs.As.
ARG
[toc] | [next] | [standalone]
| From | Lynn McGuire <lynnmcguire5@gmail.com> |
|---|---|
| Date | 2022-07-20 19:22 -0500 |
| Message-ID | <tba68s$1uiit$1@dont-email.me> |
| In reply to | #85508 |
On 7/20/2022 4:42 PM, Cholo Lennon wrote:
> I am learning Rust. One missing C++/Java feature is function
> overloading. One of the explanations of this decision is that "function
> overloading is an anti-pattern", because, among other things, "it leads
> to less readable and understandable code".
>
> This surprised me because I consider it very useful. I really hate
> having to code multiple functions with different names and almost the
> same functionality. I suffered this in Python (its solution based in
> decorators is not the best), and also in Typescript (its solution based
> in several prototypes for a single function is really awful).
>
> What is your opinion about the function overloading as an
> "anti-pattern"? is it?
>
> Disclaimer: "Overloading" where only types differ (but the number of
> parameters are the same) is possible in Rust using generic traits,
> something like the following:
>
> struct MyPrinter;
>
> trait Printer<T> {
> fn print(&self, value: T);
> }
>
> impl Printer<i32> for MyPrinter {
> fn print(&self, value: i32) {
> println!("Value: {}", value);
> }
> }
>
> impl Printer<&str> for MyPrinter {
> fn print(&self, value: &str) {
> println!("Value: {}", value);
> }
> }
>
> fn main() {
> let foo = MyPrinter;
>
> foo.print(10);
> foo.print("Hello");
> }
>
>
> --
> Cholo Lennon
> Bs.As.
> ARG
I use function overloading extensively in my C++ code code. Works
great and it is useful to have the same name with different arguments in
many classes. Here is one of my helper functions, tuple:
std::vector <int> tuple ();
std::vector <int> tuple (int int1);
std::vector <int> tuple (int int1, int int2);
std::vector <int> tuple (int int1, int int2, int int3);
std::vector <int> tuple (int int1, int int2, int int3, int int4);
std::vector <int> tuple (int int1, int int2, int int3, int int4, int int5);
std::vector <int> tuple (int int1, int int2, int int3, int int4, int
int5, int int6);
std::vector <int> tuple (int int1, int int2, int int3, int int4, int
int5, int int6, int int7);
std::vector <int> tuple (int int1, int int2, int int3, int int4, int
int5, int int6, int int7, int int8);
std::vector <int> tuple (int int1, int int2, int int3, int int4, int
int5, int int6, int int7, int int8, int int9);
std::vector <int> tuple (int int1, int int2, int int3, int int4, int
int5, int int6, int int7, int int8, int int9, int int10);
and so on to int60. I also have tupleString and tupleTuple.
I also have the following methods in my DesValue class:
virtual void setValue (int aValue);
virtual void setValue (double aValue);
virtual void setValue (char * aValue);
virtual void setValue (std::string &aValue);
virtual void setValue (std::vector <int> aValue);
virtual void setValue (std::vector <double> aValue);
virtual void setValue (std::vector <std::string> aValue);
virtual void setString ( std::string aString );
virtual void setString ( std::vector <std::string> aString );
Lynn
[toc] | [prev] | [next] | [standalone]
| From | Gawr Gura <gawrgura@mail.hololive.com> |
|---|---|
| Date | 2022-07-20 22:44 -0700 |
| Message-ID | <tbap4p$265mr$1@dont-email.me> |
| In reply to | #85515 |
On 7/20/22 17:22, Lynn McGuire wrote:
> On 7/20/2022 4:42 PM, Cholo Lennon wrote:
>> I am learning Rust. One missing C++/Java feature is function
>> overloading. One of the explanations of this decision is that
>> "function overloading is an anti-pattern", because, among other
>> things, "it leads to less readable and understandable code".
>>
>> This surprised me because I consider it very useful. I really hate
>> having to code multiple functions with different names and almost the
>> same functionality. I suffered this in Python (its solution based in
>> decorators is not the best), and also in Typescript (its solution
>> based in several prototypes for a single function is really awful).
>>
>> What is your opinion about the function overloading as an
>> "anti-pattern"? is it?
>>
>> Disclaimer: "Overloading" where only types differ (but the number of
>> parameters are the same) is possible in Rust using generic traits,
>> something like the following:
>>
>> struct MyPrinter;
>>
>> trait Printer<T> {
>> fn print(&self, value: T);
>> }
>>
>> impl Printer<i32> for MyPrinter {
>> fn print(&self, value: i32) {
>> println!("Value: {}", value);
>> }
>> }
>>
>> impl Printer<&str> for MyPrinter {
>> fn print(&self, value: &str) {
>> println!("Value: {}", value);
>> }
>> }
>>
>> fn main() {
>> let foo = MyPrinter;
>>
>> foo.print(10);
>> foo.print("Hello");
>> }
>>
>>
>> --
>> Cholo Lennon
>> Bs.As.
>> ARG
>
> I use function overloading extensively in my C++ code code. Works
> great and it is useful to have the same name with different arguments in
> many classes. Here is one of my helper functions, tuple:
>
> std::vector <int> tuple ();
> std::vector <int> tuple (int int1);
> std::vector <int> tuple (int int1, int int2);
> std::vector <int> tuple (int int1, int int2, int int3);
> std::vector <int> tuple (int int1, int int2, int int3, int int4);
> std::vector <int> tuple (int int1, int int2, int int3, int int4, int int5);
> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
> int5, int int6);
> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
> int5, int int6, int int7);
> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
> int5, int int6, int int7, int int8);
> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
> int5, int int6, int int7, int int8, int int9);
> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
> int5, int int6, int int7, int int8, int int9, int int10);
>
> and so on to int60. I also have tupleString and tupleTuple.
>
> I also have the following methods in my DesValue class:
>
> virtual void setValue (int aValue);
> virtual void setValue (double aValue);
> virtual void setValue (char * aValue);
> virtual void setValue (std::string &aValue);
> virtual void setValue (std::vector <int> aValue);
> virtual void setValue (std::vector <double> aValue);
> virtual void setValue (std::vector <std::string> aValue);
> virtual void setString ( std::string aString );
> virtual void setString ( std::vector <std::string> aString );
>
> Lynn
>
>
Is there a specific reason you've chosen to implement your tuple
function out to 60 elements rather than using a std::vector list
initializer?
[toc] | [prev] | [next] | [standalone]
| From | Lynn McGuire <lynnmcguire5@gmail.com> |
|---|---|
| Date | 2022-07-21 16:17 -0500 |
| Message-ID | <tbcfq3$2jsj1$1@dont-email.me> |
| In reply to | #85517 |
On 7/21/2022 12:44 AM, Gawr Gura wrote:
> On 7/20/22 17:22, Lynn McGuire wrote:
>> On 7/20/2022 4:42 PM, Cholo Lennon wrote:
>>> I am learning Rust. One missing C++/Java feature is function
>>> overloading. One of the explanations of this decision is that
>>> "function overloading is an anti-pattern", because, among other
>>> things, "it leads to less readable and understandable code".
>>>
>>> This surprised me because I consider it very useful. I really hate
>>> having to code multiple functions with different names and almost the
>>> same functionality. I suffered this in Python (its solution based in
>>> decorators is not the best), and also in Typescript (its solution
>>> based in several prototypes for a single function is really awful).
>>>
>>> What is your opinion about the function overloading as an
>>> "anti-pattern"? is it?
>>>
>>> Disclaimer: "Overloading" where only types differ (but the number of
>>> parameters are the same) is possible in Rust using generic traits,
>>> something like the following:
>>>
>>> struct MyPrinter;
>>>
>>> trait Printer<T> {
>>> fn print(&self, value: T);
>>> }
>>>
>>> impl Printer<i32> for MyPrinter {
>>> fn print(&self, value: i32) {
>>> println!("Value: {}", value);
>>> }
>>> }
>>>
>>> impl Printer<&str> for MyPrinter {
>>> fn print(&self, value: &str) {
>>> println!("Value: {}", value);
>>> }
>>> }
>>>
>>> fn main() {
>>> let foo = MyPrinter;
>>>
>>> foo.print(10);
>>> foo.print("Hello");
>>> }
>>>
>>>
>>> --
>>> Cholo Lennon
>>> Bs.As.
>>> ARG
>>
>> I use function overloading extensively in my C++ code code. Works
>> great and it is useful to have the same name with different arguments
>> in many classes. Here is one of my helper functions, tuple:
>>
>> std::vector <int> tuple ();
>> std::vector <int> tuple (int int1);
>> std::vector <int> tuple (int int1, int int2);
>> std::vector <int> tuple (int int1, int int2, int int3);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5, int int6);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5, int int6, int int7);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5, int int6, int int7, int int8);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5, int int6, int int7, int int8, int int9);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5, int int6, int int7, int int8, int int9, int int10);
>>
>> and so on to int60. I also have tupleString and tupleTuple.
>>
>> I also have the following methods in my DesValue class:
>>
>> virtual void setValue (int aValue);
>> virtual void setValue (double aValue);
>> virtual void setValue (char * aValue);
>> virtual void setValue (std::string &aValue);
>> virtual void setValue (std::vector <int> aValue);
>> virtual void setValue (std::vector <double> aValue);
>> virtual void setValue (std::vector <std::string> aValue);
>> virtual void setString ( std::string aString );
>> virtual void setString ( std::vector <std::string> aString );
>>
>> Lynn
>>
>>
>
> Is there a specific reason you've chosen to implement your tuple
> function out to 60 elements rather than using a std::vector list
> initializer?
I came to C++ from Smalltalk. Tuple was a standard class and function
and was easy to convert using my handwritten converter.
Lynn
[toc] | [prev] | [next] | [standalone]
| From | Cholo Lennon <chololennon@hotmail.com> |
|---|---|
| Date | 2022-07-22 19:43 -0300 |
| Message-ID | <tbf95m$fc1$1@gioia.aioe.org> |
| In reply to | #85515 |
On 7/20/22 9:22 PM, Lynn McGuire wrote:
> I use function overloading extensively in my C++ code code. Works
> great and it is useful to have the same name with different arguments in
> many classes. Here is one of my helper functions, tuple:
>
> std::vector <int> tuple ();
> std::vector <int> tuple (int int1);
> std::vector <int> tuple (int int1, int int2);
> std::vector <int> tuple (int int1, int int2, int int3);
> std::vector <int> tuple (int int1, int int2, int int3, int int4);
> std::vector <int> tuple (int int1, int int2, int int3, int int4, int int5);
> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
> int5, int int6);
> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
> int5, int int6, int int7);
> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
> int5, int int6, int int7, int int8);
> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
> int5, int int6, int int7, int int8, int int9);
> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
> int5, int int6, int int7, int int8, int int9, int int10);
>
> and so on to int60. I also have tupleString and tupleTuple.
I suppose your code was written before C++11. Nowadays I would write
something like this:
template<typename T>
auto tuple() -> std::vector<T> {
return std::vector<T>{};
}
template<typename T, typename... Args>
auto tuple(const T& first, const Args&... args) -> std::vector<T> {
return std::vector<T>{ first, args... };
}
Or just use std::vector list initializer as suggested by Gawr Gura.
--
Cholo Lennon
Bs.As.
ARG
[toc] | [prev] | [next] | [standalone]
| From | Lynn McGuire <lynnmcguire5@gmail.com> |
|---|---|
| Date | 2022-07-22 18:38 -0500 |
| Message-ID | <tbfcei$3eapa$1@dont-email.me> |
| In reply to | #85571 |
On 7/22/2022 5:43 PM, Cholo Lennon wrote:
> On 7/20/22 9:22 PM, Lynn McGuire wrote:
>> I use function overloading extensively in my C++ code code. Works
>> great and it is useful to have the same name with different arguments
>> in many classes. Here is one of my helper functions, tuple:
>>
>> std::vector <int> tuple ();
>> std::vector <int> tuple (int int1);
>> std::vector <int> tuple (int int1, int int2);
>> std::vector <int> tuple (int int1, int int2, int int3);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5, int int6);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5, int int6, int int7);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5, int int6, int int7, int int8);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5, int int6, int int7, int int8, int int9);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5, int int6, int int7, int int8, int int9, int int10);
>>
>> and so on to int60. I also have tupleString and tupleTuple.
>
> I suppose your code was written before C++11. Nowadays I would write
> something like this:
>
> template<typename T>
> auto tuple() -> std::vector<T> {
> return std::vector<T>{};
> }
>
> template<typename T, typename... Args>
> auto tuple(const T& first, const Args&... args) -> std::vector<T> {
> return std::vector<T>{ first, args... };
> }
>
> Or just use std::vector list initializer as suggested by Gawr Gura.
>
>
> --
> Cholo Lennon
> Bs.As.
> ARG
My tuple functions were written in 2002 in my port from Smalltalk to
C++. Did std::vector have an initializer back then ? My Smalltalk
conpiler had a heterogeneous collection library using the tuple method
so I wanted a straight conversion between the two. Luckily, most of my
Smalltalk tuples were actually homogeneous collections.
Lynn
[toc] | [prev] | [next] | [standalone]
| From | Cholo Lennon <chololennon@hotmail.com> |
|---|---|
| Date | 2022-07-24 01:24 -0300 |
| Message-ID | <tbihhd$1gi1$1@gioia.aioe.org> |
| In reply to | #85572 |
On 7/22/22 20:38, Lynn McGuire wrote:
> On 7/22/2022 5:43 PM, Cholo Lennon wrote:
>> On 7/20/22 9:22 PM, Lynn McGuire wrote:
>>> I use function overloading extensively in my C++ code code. Works
>>> great and it is useful to have the same name with different arguments
>>> in many classes. Here is one of my helper functions, tuple:
>>>
>>> std::vector <int> tuple ();
>>> std::vector <int> tuple (int int1);
>>> std::vector <int> tuple (int int1, int int2);
>>> std::vector <int> tuple (int int1, int int2, int int3);
>>> std::vector <int> tuple (int int1, int int2, int int3, int int4);
>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>> int5);
>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>> int5, int int6);
>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>> int5, int int6, int int7);
>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>> int5, int int6, int int7, int int8);
>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>> int5, int int6, int int7, int int8, int int9);
>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>> int5, int int6, int int7, int int8, int int9, int int10);
>>>
>>> and so on to int60. I also have tupleString and tupleTuple.
>>
>> I suppose your code was written before C++11. Nowadays I would write
>> something like this:
>>
>> template<typename T>
>> auto tuple() -> std::vector<T> {
>> return std::vector<T>{};
>> }
>>
>> template<typename T, typename... Args>
>> auto tuple(const T& first, const Args&... args) -> std::vector<T> {
>> return std::vector<T>{ first, args... };
>> }
>>
>> Or just use std::vector list initializer as suggested by Gawr Gura.
>>
>>
>> --
>> Cholo Lennon
>> Bs.As.
>> ARG
>
> My tuple functions were written in 2002 in my port from Smalltalk to
> C++. Did std::vector have an initializer back then ?
Why the rhetoric question? (both know that std::vector hadn't that in
2002). I explicitly said "I suppose your code was written before C++11.
Nowadays I would write...".
--
Cholo Lennon
Bs.As.
ARG
[toc] | [prev] | [next] | [standalone]
| From | Lynn McGuire <lynnmcguire5@gmail.com> |
|---|---|
| Date | 2022-07-25 16:01 -0500 |
| Message-ID | <tbn0c2$1emem$2@dont-email.me> |
| In reply to | #85578 |
On 7/23/2022 11:24 PM, Cholo Lennon wrote:
> On 7/22/22 20:38, Lynn McGuire wrote:
>> On 7/22/2022 5:43 PM, Cholo Lennon wrote:
>>> On 7/20/22 9:22 PM, Lynn McGuire wrote:
>>>> I use function overloading extensively in my C++ code code. Works
>>>> great and it is useful to have the same name with different
>>>> arguments in many classes. Here is one of my helper functions, tuple:
>>>>
>>>> std::vector <int> tuple ();
>>>> std::vector <int> tuple (int int1);
>>>> std::vector <int> tuple (int int1, int int2);
>>>> std::vector <int> tuple (int int1, int int2, int int3);
>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4);
>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>>> int5);
>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>>> int5, int int6);
>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>>> int5, int int6, int int7);
>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>>> int5, int int6, int int7, int int8);
>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>>> int5, int int6, int int7, int int8, int int9);
>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>>> int5, int int6, int int7, int int8, int int9, int int10);
>>>>
>>>> and so on to int60. I also have tupleString and tupleTuple.
>>>
>>> I suppose your code was written before C++11. Nowadays I would write
>>> something like this:
>>>
>>> template<typename T>
>>> auto tuple() -> std::vector<T> {
>>> return std::vector<T>{};
>>> }
>>>
>>> template<typename T, typename... Args>
>>> auto tuple(const T& first, const Args&... args) -> std::vector<T> {
>>> return std::vector<T>{ first, args... };
>>> }
>>>
>>> Or just use std::vector list initializer as suggested by Gawr Gura.
>>>
>>>
>>> --
>>> Cholo Lennon
>>> Bs.As.
>>> ARG
>>
>> My tuple functions were written in 2002 in my port from Smalltalk to
>> C++. Did std::vector have an initializer back then ?
>
> Why the rhetoric question? (both know that std::vector hadn't that in
> 2002). I explicitly said "I suppose your code was written before C++11.
> Nowadays I would write...".
>
>
> --
> Cholo Lennon
> Bs.As.
> ARG
Sorry, I do not remember when new features came into languages. I have
written software in ten computer languages now. I am approaching a
million lines of code now, it is hard to remember details.
Lynn
[toc] | [prev] | [next] | [standalone]
| From | "Alf P. Steinbach" <alf.p.steinbach@gmail.com> |
|---|---|
| Date | 2022-07-26 00:05 +0200 |
| Message-ID | <tbn442$1g2fd$1@dont-email.me> |
| In reply to | #85628 |
On 25 Jul 2022 23:01, Lynn McGuire wrote: > > Sorry, I do not remember when new features came into languages. I have > written software in ten computer languages now. I am approaching a > million lines of code now, it is hard to remember details. A nice summary of which features were introduced when, for C++. With discussion of the features. <url: https://github.com/AnthonyCalandra/modern-cpp-features> - Alf
[toc] | [prev] | [next] | [standalone]
| From | Cholo Lennon <chololennon@hotmail.com> |
|---|---|
| Date | 2022-07-30 18:04 -0300 |
| Message-ID | <tc46dl$1ths$2@gioia.aioe.org> |
| In reply to | #85631 |
On 7/25/22 19:05, Alf P. Steinbach wrote: > On 25 Jul 2022 23:01, Lynn McGuire wrote: >> >> Sorry, I do not remember when new features came into languages. I >> have written software in ten computer languages now. I am approaching >> a million lines of code now, it is hard to remember details. > > A nice summary of which features were introduced when, for C++. > > With discussion of the features. > > <url: https://github.com/AnthonyCalandra/modern-cpp-features> > Thanks, very useful :-) I didn't know it. -- Cholo Lennon Bs.As. ARG
[toc] | [prev] | [next] | [standalone]
| From | Cholo Lennon <chololennon@hotmail.com> |
|---|---|
| Date | 2022-07-30 18:03 -0300 |
| Message-ID | <tc46bn$1ths$1@gioia.aioe.org> |
| In reply to | #85628 |
On 7/25/22 18:01, Lynn McGuire wrote:
> On 7/23/2022 11:24 PM, Cholo Lennon wrote:
>> On 7/22/22 20:38, Lynn McGuire wrote:
>>> On 7/22/2022 5:43 PM, Cholo Lennon wrote:
>>>> On 7/20/22 9:22 PM, Lynn McGuire wrote:
>>>>> I use function overloading extensively in my C++ code code. Works
>>>>> great and it is useful to have the same name with different
>>>>> arguments in many classes. Here is one of my helper functions, tuple:
>>>>>
>>>>> std::vector <int> tuple ();
>>>>> std::vector <int> tuple (int int1);
>>>>> std::vector <int> tuple (int int1, int int2);
>>>>> std::vector <int> tuple (int int1, int int2, int int3);
>>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4);
>>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4,
>>>>> int int5);
>>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4,
>>>>> int int5, int int6);
>>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4,
>>>>> int int5, int int6, int int7);
>>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4,
>>>>> int int5, int int6, int int7, int int8);
>>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4,
>>>>> int int5, int int6, int int7, int int8, int int9);
>>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4,
>>>>> int int5, int int6, int int7, int int8, int int9, int int10);
>>>>>
>>>>> and so on to int60. I also have tupleString and tupleTuple.
>>>>
>>>> I suppose your code was written before C++11. Nowadays I would write
>>>> something like this:
>>>>
>>>> template<typename T>
>>>> auto tuple() -> std::vector<T> {
>>>> return std::vector<T>{};
>>>> }
>>>>
>>>> template<typename T, typename... Args>
>>>> auto tuple(const T& first, const Args&... args) ->
>>>> std::vector<T> {
>>>> return std::vector<T>{ first, args... };
>>>> }
>>>>
>>>> Or just use std::vector list initializer as suggested by Gawr Gura.
>>>>
>>>>
>>>> --
>>>> Cholo Lennon
>>>> Bs.As.
>>>> ARG
>>>
>>> My tuple functions were written in 2002 in my port from Smalltalk to
>>> C++. Did std::vector have an initializer back then ?
>>
>> Why the rhetoric question? (both know that std::vector hadn't that in
>> 2002). I explicitly said "I suppose your code was written before
>> C++11. Nowadays I would write...".
>>
>>
>> --
>> Cholo Lennon
>> Bs.As.
>> ARG
>
> Sorry, I do not remember when new features came into languages. I have
> written software in ten computer languages now. I am approaching a
> million lines of code now, it is hard to remember details.
>
Thanks for the clarification, I wrongly assumed that in this newsgroup,
everyone knows more or less, when some features where implemented.
Regards
--
Cholo Lennon
Bs.As.
ARG
[toc] | [prev] | [next] | [standalone]
| From | Lynn McGuire <lynnmcguire5@gmail.com> |
|---|---|
| Date | 2022-08-02 23:11 -0500 |
| Message-ID | <tccshq$20da9$2@dont-email.me> |
| In reply to | #85758 |
On 7/30/2022 4:03 PM, Cholo Lennon wrote:
> On 7/25/22 18:01, Lynn McGuire wrote:
>> On 7/23/2022 11:24 PM, Cholo Lennon wrote:
>>> On 7/22/22 20:38, Lynn McGuire wrote:
>>>> On 7/22/2022 5:43 PM, Cholo Lennon wrote:
>>>>> On 7/20/22 9:22 PM, Lynn McGuire wrote:
>>>>>> I use function overloading extensively in my C++ code code.
>>>>>> Works great and it is useful to have the same name with different
>>>>>> arguments in many classes. Here is one of my helper functions,
>>>>>> tuple:
>>>>>>
>>>>>> std::vector <int> tuple ();
>>>>>> std::vector <int> tuple (int int1);
>>>>>> std::vector <int> tuple (int int1, int int2);
>>>>>> std::vector <int> tuple (int int1, int int2, int int3);
>>>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4);
>>>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4,
>>>>>> int int5);
>>>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4,
>>>>>> int int5, int int6);
>>>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4,
>>>>>> int int5, int int6, int int7);
>>>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4,
>>>>>> int int5, int int6, int int7, int int8);
>>>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4,
>>>>>> int int5, int int6, int int7, int int8, int int9);
>>>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4,
>>>>>> int int5, int int6, int int7, int int8, int int9, int int10);
>>>>>>
>>>>>> and so on to int60. I also have tupleString and tupleTuple.
>>>>>
>>>>> I suppose your code was written before C++11. Nowadays I would
>>>>> write something like this:
>>>>>
>>>>> template<typename T>
>>>>> auto tuple() -> std::vector<T> {
>>>>> return std::vector<T>{};
>>>>> }
>>>>>
>>>>> template<typename T, typename... Args>
>>>>> auto tuple(const T& first, const Args&... args) ->
>>>>> std::vector<T> {
>>>>> return std::vector<T>{ first, args... };
>>>>> }
>>>>>
>>>>> Or just use std::vector list initializer as suggested by Gawr Gura.
>>>>>
>>>>>
>>>>> --
>>>>> Cholo Lennon
>>>>> Bs.As.
>>>>> ARG
>>>>
>>>> My tuple functions were written in 2002 in my port from Smalltalk to
>>>> C++. Did std::vector have an initializer back then ?
>>>
>>> Why the rhetoric question? (both know that std::vector hadn't that in
>>> 2002). I explicitly said "I suppose your code was written before
>>> C++11. Nowadays I would write...".
>>>
>>>
>>> --
>>> Cholo Lennon
>>> Bs.As.
>>> ARG
>>
>> Sorry, I do not remember when new features came into languages. I
>> have written software in ten computer languages now. I am approaching
>> a million lines of code now, it is hard to remember details.
>>
>
> Thanks for the clarification, I wrongly assumed that in this newsgroup,
> everyone knows more or less, when some features where implemented.
>
> Regards
>
> --
> Cholo Lennon
> Bs.As.
> ARG
I had some serious problems in the port from Smalltalk to C++. The
biggest problem was that objects in Smalltalk are not typed until
runtime (all declared as type var). Whereas, objects in C++ are typed
at compile time (mostly kinda). I used my tuple methods and many other
methods to help with the typing, it made our jobs easier as my
handwritten conversion tool typed all objects as ObjPtr. After
conversion, the programmer typed all of the objects in the converted C++
code. If there was a mistake, the compiler usually yelled at us.
Lynn
[toc] | [prev] | [next] | [standalone]
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Date | 2022-07-27 16:10 +0200 |
| Message-ID | <tbrgtr$2hhij$1@dont-email.me> |
| In reply to | #85515 |
Am 21.07.2022 um 02:22 schrieb Lynn McGuire:
> std::vector <int> tuple ();
> std::vector <int> tuple (int int1);
> std::vector <int> tuple (int int1, int int2);
> std::vector <int> tuple (int int1, int int2, int int3);
> std::vector <int> tuple (int int1, int int2, int int3, int int4);
> std::vector <int> tuple (int int1, int int2, int int3, int int4, int int5);
> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
> int5, int int6);
> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
> int5, int int6, int int7);
> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
> int5, int int6, int int7, int int8);
> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
> int5, int int6, int int7, int int8, int int9);
> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
> int5, int int6, int int7, int int8, int int9, int int10);
You can have that easier:
template<typename To, typename ... Ts>
vector<To> myTuple( Ts &&... params )
requires (convertible_to<Ts, To> && ...)
{
vector<To> vt;
vt.reserve( sizeof ...(Ts) );
auto make_row = [&]<size_t ... Indices>( index_sequence<Indices ...> )
{
((Indices, vt.emplace_back( params )), ...);
};
make_row( make_index_sequence<sizeof ...(Ts)>() );
return vt;
}
Works with an arbitrary number of parameters.
[toc] | [prev] | [next] | [standalone]
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Date | 2022-07-27 16:11 +0200 |
| Message-ID | <tbrh04$2hhij$2@dont-email.me> |
| In reply to | #85687 |
Am 27.07.2022 um 16:10 schrieb Bonita Montero:
> template<typename To, typename ... Ts>
> vector<To> myTuple( Ts &&... params )
> requires (convertible_to<Ts, To> && ...)
> {
> vector<To> vt;
> vt.reserve( sizeof ...(Ts) );
> auto make_row = [&]<size_t ... Indices>( index_sequence<Indices ...> )
> {
> ((Indices, vt.emplace_back( params )), ...);
> };
> make_row( make_index_sequence<sizeof ...(Ts)>() );
> return vt;
> }
Now it's complete, I fogot to forward:
template<typename To, typename ... Ts>
vector<To> myTuple( Ts &&... params )
requires (convertible_to<Ts, To> && ...)
{
vector<To> vt;
vt.reserve( sizeof ...(Ts) );
auto make_row = [&]<size_t ... Indices>( index_sequence<Indices ...> )
{
((Indices, vt.emplace_back( forward<Ts>( params ) )), ...);
};
make_row( make_index_sequence<sizeof ...(Ts)>() );
return vt;
}
[toc] | [prev] | [next] | [standalone]
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Date | 2022-07-27 16:35 +0200 |
| Message-ID | <tbriec$2hn9e$1@dont-email.me> |
| In reply to | #85687 |
Am 27.07.2022 um 16:10 schrieb Bonita Montero:
> You can have that easier:
>
> template<typename To, typename ... Ts>
> vector<To> myTuple( Ts &&... params )
> requires (convertible_to<Ts, To> && ...)
> {
> vector<To> vt;
> vt.reserve( sizeof ...(Ts) );
> auto make_row = [&]<size_t ... Indices>( index_sequence<Indices ...> )
> {
> ((Indices, vt.emplace_back( params )), ...);
> };
> make_row( make_index_sequence<sizeof ...(Ts)>() );
> return vt;
> }
>
> Works with an arbitrary number of parameters.
This is even more convenient:
template<typename ... Ts>
requires (sizeof ...(Ts) >= 1) && (convertible_to<Ts,
tuple_element_t<0, tuple<Ts ...>>> && ...)
vector<tuple_element_t<0, tuple<Ts ...>>> myTuple( Ts &&... params )
{
vector<tuple_element_t<0, tuple<Ts ...>>> vt;
vt.reserve( sizeof ...(Ts) );
auto make_row = [&]<size_t ... Indices>( index_sequence<Indices ...> )
{
((Indices, vt.emplace_back( forward<Ts>( params ) )), ...);
};
make_row( make_index_sequence<sizeof ...(Ts)>() );
return vt;
}
[toc] | [prev] | [next] | [standalone]
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Date | 2022-07-28 05:51 +0200 |
| Message-ID | <tbt12d$2qrbt$1@dont-email.me> |
| In reply to | #85689 |
Am 27.07.2022 um 16:35 schrieb Bonita Montero:
> Am 27.07.2022 um 16:10 schrieb Bonita Montero:
>
>> You can have that easier:
>>
>> template<typename To, typename ... Ts>
>> vector<To> myTuple( Ts &&... params )
>> requires (convertible_to<Ts, To> && ...)
>> {
>> vector<To> vt;
>> vt.reserve( sizeof ...(Ts) );
>> auto make_row = [&]<size_t ... Indices>( index_sequence<Indices
>> ...> )
>> {
>> ((Indices, vt.emplace_back( params )), ...);
>> };
>> make_row( make_index_sequence<sizeof ...(Ts)>() );
>> return vt;
>> }
>>
>> Works with an arbitrary number of parameters.
>
> This is even more convenient:
>
> template<typename ... Ts>
> requires (sizeof ...(Ts) >= 1) && (convertible_to<Ts,
> tuple_element_t<0, tuple<Ts ...>>> && ...)
> vector<tuple_element_t<0, tuple<Ts ...>>> myTuple( Ts &&... params )
> {
> vector<tuple_element_t<0, tuple<Ts ...>>> vt;
> vt.reserve( sizeof ...(Ts) );
> auto make_row = [&]<size_t ... Indices>( index_sequence<Indices ...> )
> {
> ((Indices, vt.emplace_back( forward<Ts>( params ) )), ...);
> };
> make_row( make_index_sequence<sizeof ...(Ts)>() );
> return vt;
> }
>
It can be even simpler:
template<typename ... Ts>
requires (sizeof ...(Ts) >= 1) && (convertible_to<Ts,
tuple_element_t<0, tuple<Ts ...>>> && ...)
vector<tuple_element_t<0, tuple<Ts ...>>> myTuple( Ts &&... params )
{
vector<tuple_element_t<0, tuple<Ts ...>>> vt;
vt.reserve( sizeof ...(Ts) );
(vt.emplace_back( forward<Ts>( params ) ), ...);
return vt;
}
[toc] | [prev] | [next] | [standalone]
| From | Lynn McGuire <lynnmcguire5@gmail.com> |
|---|---|
| Date | 2022-07-27 14:54 -0500 |
| Message-ID | <tbs56f$2k18i$1@dont-email.me> |
| In reply to | #85687 |
On 7/27/2022 9:10 AM, Bonita Montero wrote:
> Am 21.07.2022 um 02:22 schrieb Lynn McGuire:
>
>> std::vector <int> tuple ();
>> std::vector <int> tuple (int int1);
>> std::vector <int> tuple (int int1, int int2);
>> std::vector <int> tuple (int int1, int int2, int int3);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5, int int6);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5, int int6, int int7);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5, int int6, int int7, int int8);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5, int int6, int int7, int int8, int int9);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5, int int6, int int7, int int8, int int9, int int10);
>
> You can have that easier:
>
> template<typename To, typename ... Ts>
> vector<To> myTuple( Ts &&... params )
> requires (convertible_to<Ts, To> && ...)
> {
> vector<To> vt;
> vt.reserve( sizeof ...(Ts) );
> auto make_row = [&]<size_t ... Indices>( index_sequence<Indices ...> )
> {
> ((Indices, vt.emplace_back( params )), ...);
> };
> make_row( make_index_sequence<sizeof ...(Ts)>() );
> return vt;
> }
>
> Works with an arbitrary number of parameters.
Sorry, I do not allow templates in our software. We have found out the
hard way that templates need to be written with many problems in mind.
Lynn
[toc] | [prev] | [next] | [standalone]
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Date | 2022-07-28 05:43 +0200 |
| Message-ID | <tbt0jd$2qnn4$1@dont-email.me> |
| In reply to | #85702 |
Am 27.07.2022 um 21:54 schrieb Lynn McGuire:
> On 7/27/2022 9:10 AM, Bonita Montero wrote:
>> Am 21.07.2022 um 02:22 schrieb Lynn McGuire:
>>
>>> std::vector <int> tuple ();
>>> std::vector <int> tuple (int int1);
>>> std::vector <int> tuple (int int1, int int2);
>>> std::vector <int> tuple (int int1, int int2, int int3);
>>> std::vector <int> tuple (int int1, int int2, int int3, int int4);
>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>> int5);
>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>> int5, int int6);
>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>> int5, int int6, int int7);
>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>> int5, int int6, int int7, int int8);
>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>> int5, int int6, int int7, int int8, int int9);
>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>> int5, int int6, int int7, int int8, int int9, int int10);
>>
>> You can have that easier:
>>
>> template<typename To, typename ... Ts>
>> vector<To> myTuple( Ts &&... params )
>> requires (convertible_to<Ts, To> && ...)
>> {
>> vector<To> vt;
>> vt.reserve( sizeof ...(Ts) );
>> auto make_row = [&]<size_t ... Indices>( index_sequence<Indices
>> ...> )
>> {
>> ((Indices, vt.emplace_back( params )), ...);
>> };
>> make_row( make_index_sequence<sizeof ...(Ts)>() );
>> return vt;
>> }
>>
>> Works with an arbitrary number of parameters.
>
> Sorry, I do not allow templates in our software. We have found out the
> hard way that templates need to be written with many problems in mind.
That's really stupid.
[toc] | [prev] | [next] | [standalone]
| From | Lynn McGuire <lynnmcguire5@gmail.com> |
|---|---|
| Date | 2022-07-28 13:32 -0500 |
| Message-ID | <tbukn8$37lvb$1@dont-email.me> |
| In reply to | #85709 |
On 7/27/2022 10:43 PM, Bonita Montero wrote:
> Am 27.07.2022 um 21:54 schrieb Lynn McGuire:
>> On 7/27/2022 9:10 AM, Bonita Montero wrote:
>>> Am 21.07.2022 um 02:22 schrieb Lynn McGuire:
>>>
>>>> std::vector <int> tuple ();
>>>> std::vector <int> tuple (int int1);
>>>> std::vector <int> tuple (int int1, int int2);
>>>> std::vector <int> tuple (int int1, int int2, int int3);
>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4);
>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>>> int5);
>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>>> int5, int int6);
>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>>> int5, int int6, int int7);
>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>>> int5, int int6, int int7, int int8);
>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>>> int5, int int6, int int7, int int8, int int9);
>>>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>>>> int5, int int6, int int7, int int8, int int9, int int10);
>>>
>>> You can have that easier:
>>>
>>> template<typename To, typename ... Ts>
>>> vector<To> myTuple( Ts &&... params )
>>> requires (convertible_to<Ts, To> && ...)
>>> {
>>> vector<To> vt;
>>> vt.reserve( sizeof ...(Ts) );
>>> auto make_row = [&]<size_t ... Indices>( index_sequence<Indices
>>> ...> )
>>> {
>>> ((Indices, vt.emplace_back( params )), ...);
>>> };
>>> make_row( make_index_sequence<sizeof ...(Ts)>() );
>>> return vt;
>>> }
>>>
>>> Works with an arbitrary number of parameters.
>>
>> Sorry, I do not allow templates in our software. We have found out
>> the hard way that templates need to be written with many problems in
>> mind.
>
> That's really stupid.
Thank you.
Lynn
[toc] | [prev] | [next] | [standalone]
| From | Lynn McGuire <lynnmcguire5@gmail.com> |
|---|---|
| Date | 2022-07-27 15:01 -0500 |
| Message-ID | <tbs5i7$2k18i$2@dont-email.me> |
| In reply to | #85687 |
On 7/27/2022 9:10 AM, Bonita Montero wrote:
> Am 21.07.2022 um 02:22 schrieb Lynn McGuire:
>
>> std::vector <int> tuple ();
>> std::vector <int> tuple (int int1);
>> std::vector <int> tuple (int int1, int int2);
>> std::vector <int> tuple (int int1, int int2, int int3);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5, int int6);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5, int int6, int int7);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5, int int6, int int7, int int8);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5, int int6, int int7, int int8, int int9);
>> std::vector <int> tuple (int int1, int int2, int int3, int int4, int
>> int5, int int6, int int7, int int8, int int9, int int10);
>
> You can have that easier:
>
> template<typename To, typename ... Ts>
> vector<To> myTuple( Ts &&... params )
> requires (convertible_to<Ts, To> && ...)
> {
> vector<To> vt;
> vt.reserve( sizeof ...(Ts) );
> auto make_row = [&]<size_t ... Indices>( index_sequence<Indices ...> )
> {
> ((Indices, vt.emplace_back( params )), ...);
> };
> make_row( make_index_sequence<sizeof ...(Ts)>() );
> return vt;
> }
>
> Works with an arbitrary number of parameters.
Also, most of my tuples are built at compile time. They have really
worked well for us for over 20 years. I just noted that I have over
2,900 tuples, tupleStrings, and tupleTuples in my code.
Lynn
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.c++
csiph-web