I want to access template parameter. This code works :-
template<int s1,int s2> class Setting{public:
static const int setting1=s1;
static const int setting2=s2;
};
class Album{
public: using Setting_unique =Setting<1,2> ;
public: using Setting_share =Setting<4,7> ;
};
template<class Setting_X> class SmartPtr{
public: void doSomething(){
if constexpr(Setting_X::setting1==1){
// ^ intellisense sad :(
}
}
};
int main(){ SmartPtr<Album::Setting_unique> a; }
^ However, the intellisense is not happy with it.
I can't do my ctrl+space
.
Below is my trick to make Intellisense works again. It also works :-
class Helper{public: // **new class**
int setting1=0;
int setting2=0;
public: constexpr Helper(int setting1P,int setting2P)
: setting1(setting1P), setting2(setting2P){ }
};
template<int s1,int s2> class Setting{
// **new function**
public: static constexpr Helper getHelper(){return Helper(s1,s2);}
};
class Album{
public: using Setting_unique =Setting<1,2> ;
public: using Setting_share =Setting<4,7> ;
};
template<class Setting_X> class SmartPtr{
static constexpr Helper setting = Setting_X::getHelper();
public: void doSomething(){
if constexpr(setting.setting1==1){
// ^ intellisense happy :) -
// It shows "setting1" & "setting2" in a drop-down list.
}
}
};
int main(){SmartPtr<Album::Setting_unique> a; }
Here is the drop down list I desire :-
The problem is : my code becomes harder to refactor and dirtier.
If I may add a new s3
in the future, there are more locations of codes waiting to be edited.
How to make the intellisense happy, while keep the maintainability-level?
I am using Visual Studio 2017 + Resharper.
(optional) However, it would be cool if the solution doesn't depends on Resharper.
(optional) It would be ideal if the solution can be applied to most IDEs as well.
Sorry if this question may sound trivial, but ctrl+space
is my life.
Aucun commentaire:
Enregistrer un commentaire