C++ function/member templates

Please use this forum to ask for a new feature or to change an existing feature.
Merci d'utiliser ce forum pour demander de nouvelles fonctionnalités ou la modification de fonctionnalités existantes.

C++ function/member templates

Postby kikeenrique » Tue 16 Oct 2018 17:21

Hello again,

Would it be possible, or is it possible at the moment, to write function or members templates?

I’m currently using a templated class with just one member function to represent this, but I think it’s a workaround.

Regards
kikeenrique
 
Posts: 6
Joined: Tue 24 Jul 2018 09:52

Re: C++ function/member templates

Postby Bruno Pagès » Wed 17 Oct 2018 08:36

Hello,

You cannot model a function/member out of a class, so yes you have to place them into a class, having a very reduced definition like ${members}

It is not mandatory to use a templated class even this can be more practical, the template<...> header can be insert directly into the function/member definition

You can also define the function/member directly into an artifact definition, but in that case this is just a text, not a modelization

Kind regards
ImageAuthor of Bouml
Bruno Pagès
 
Posts: 600
Joined: Mon 20 Feb 2012 09:23
Location: France

Re: C++ function/member templates

Postby kikeenrique » Wed 17 Oct 2018 09:50

I’m going to elaborate a bit more my proposal, as I didn’t fully understand your answer.

Your indication with the template<...> would be only for the c++ tab definition, not for modeling, did I understand properly?
I would be interested in modeling templated member functions, individually, in a class.

Currently to model a class template you can do it using the “parameterized” tab. There you can set as many template parameters as you want. That’s perfect.

But, when defining a class method/operation, you can’t set templated parameters specific for that method.
Maybe it would possible to add a new parameterized/template tab into the method/operator dialog.
Then, when setting method parameter types, you could use class template parameters, which it’s already available, or the method template parameters, which would be the ones declared in the new proposed tab.

Do you think it’s interesting?
kikeenrique
 
Posts: 6
Joined: Tue 24 Jul 2018 09:52

Re: C++ function/member templates

Postby Bruno Pagès » Wed 17 Oct 2018 17:04

kikeenrique wrote:Your indication with the template<...> would be only for the c++ tab definition, not for modeling, did I understand properly?

yes

kikeenrique wrote:I would be interested in modeling templated member functions, individually, in a class.
...


As you know the operations of a template class have to respect the template parameters list, for instance in
Code: Select all
template<class T, class V>
class C {
  public:
    inline void op();
    inline void op2();
    inline void op3();
};

template<class T, class V>
inline void C<T, V>::op() {
}

template<class T>
inline void C<T>::op2() {
}

template<class T, class V, class W>
inline void C<T, V, W>::op3() {
}

the definition of op2 and op3 are illegal because I removed/added a template parameter.

So frankly I am not ready to add a template parameter tab in the operation to help to produce an illegal code

If by chance you have several definitions sharing the same template parameters I agree you can put them in a pseudo templated class (whose do not generate a class but only its members).
Else to define several pseudo templated classes each for one definition is heavy for nothing, again it is better to have only one pseudo class containing the members independently of their template parameters list and to add by hand the expected template<...> in their C++ declarations/definitions
ImageAuthor of Bouml
Bruno Pagès
 
Posts: 600
Joined: Mon 20 Feb 2012 09:23
Location: France


Return to Change requests / Demandes d'évolution

Who is online

Users browsing this forum: No registered users and 1 guest

cron