Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #85572
| From | Lynn McGuire <lynnmcguire5@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Function overloading |
| Date | 2022-07-22 18:38 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <tbfcei$3eapa$1@dont-email.me> (permalink) |
| References | <tb9ssj$s32$1@gioia.aioe.org> <tba68s$1uiit$1@dont-email.me> <tbf95m$fc1$1@gioia.aioe.org> |
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
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web