を返す関数の型を取得できません。私はクラスのプロパティシステムを使用しようとしているconstexprの自動
プロパティを一意に識別するための対応するメンバーポインタ、名前及び(列挙から)INTを有します。ここで
は、プロパティを定義するコードは次のとおりです。
template<typename Class, typename T>
struct MemberProperty
{
constexpr MemberProperty(T Class::*aMember, const char* aName, int aId)
: member(aMember), name(aName), id(aId)
{}
T Class::*member;
const char* name;
int id;
};
私は、この関数を呼び出してプロパティを作成します。
template <typename Class, typename T>
constexpr auto makeProperty(T Class::*member, const char* name, int id) {
return MemberProperty<Class, T>{member, name, id};
}
は、私の目標は、このようなクラスのプロパティを定義することです:
class User
{
public:
enum PropertiesEnum
{
Property_Name
};
string m_name;
static constexpr auto Properties() {
return std::make_tuple(
makeProperty(&User::m_name, "name", User::Property_Name)
);
}
using PropertiesType = decltype(Properties());
//PropertyManager<PropertiesType> m_propertyManager;
};
私は宣言する行のコメントを解除できるようにしたいと思いますm_propertyManager
。 これはコンパイルされないという問題があります。グラム++では、私が取得:
error: use of 'static constexpr auto User::Properties()' before deduction of 'auto'
のVisual Studio 2015では、私が取得:
error C3779: 'User::UserProperties': a function that returns 'auto' cannot be used before it is defined
がどのように私はこの作業を行うことができますか?それは世俗的な依存関係のように見えますが、私はそれを動作させる方法を見つけることができません。私はそれが[class.mem]/6によるものだと思い
http://coliru.stacked-crooked.com/a/24e7f5ea7f83da6f
宣言の中で、 ' - > decltype(std :: make_tuple(makeProperty(&User :: m_name、" name "、User :: Property_Name)))'が助けてくれたと思う... [ライブデモ](http:// coliru.stacked-crooked.com/a/a7f291a384992464) –
ありがとうございました。しかし、別の方法がありますか? make_tupleのパラメータは潜在的に非常に大きいです(私は多くのプロパティを追加します)。 – Michael
私は通常、これらの繰り返しを避けるためにMACROを使います。 } ' – Jarod42