Research: this is similar but doesn't fit http://stackoverflow.com/questions/3027067/optional-member-objectshttps://stackoverflow.com/questions/3027067/optional-member-objects This is similar, but again doesn't seem to fit Checking for the presence of optional properties of an object
Research: this is similar but doesn't fit http://stackoverflow.com/questions/3027067/optional-member-objects This is similar, but again doesn't seem to fit Checking for the presence of optional properties of an object
Research: this is similar but doesn't fit https://stackoverflow.com/questions/3027067/optional-member-objects This is similar, but again doesn't seem to fit Checking for the presence of optional properties of an object
Research: this is similar but doesn't fit http://stackoverflow.com/questions/3027067/optional-member-objects This is similar, but again doesn't seem to fit http://programmers.stackexchange.com/questions/236798/checking-for-the-presence-of-optional-properties-of-an-objectChecking for the presence of optional properties of an object
Research: this is similar but doesn't fit http://stackoverflow.com/questions/3027067/optional-member-objects This is similar, but again doesn't seem to fit http://programmers.stackexchange.com/questions/236798/checking-for-the-presence-of-optional-properties-of-an-object
Research: this is similar but doesn't fit http://stackoverflow.com/questions/3027067/optional-member-objects This is similar, but again doesn't seem to fit Checking for the presence of optional properties of an object
<person> <name>Fred</name> <favorite-color>Blue</favorite-color> </person> <person> <name>Fred</name> <favorite-color>Blue</favorite-color> </person> using Name = std::string; using NamePtr = std::shared_ptr<Name>; using FavoriteColor = std::string; using FavoriteColorPtr = std::shared_ptr<FavoriteColor>; /* Version 1: nullptr indicates FavoriteColor is absent, but Name will never be null because it is required */ class Person { public: Person() :myName( std::make_shared<Name>() ) ,myFavoriteColor() {} NamePtr getName() const { return myName; } void setName( const NamePtr& value ) { if( value ) { myName = value; } } FavoriteColorPtr getFavoriteColor() const { return myFavoriteColor; } void setFavoriteColor( const FavoriteColorPtr& value ) { myFavoriteColor = value; } private: NamePtr myName; FavoriteColorPtr myFavoriteColor; }; /* Version 2: FavoriteColor and Name can both be trusted to not be null, but you have to check HasFavoriteColor bool to see whether the optional data is legit */ class Person2 { public: Person2() :myName( std::make_shared<Name>() ) ,myFavoriteColor( std::make_shared<FavoriteColor>() ) {} NamePtr getName() const { return myName; } void setName( const NamePtr& value ) { if( value ) { myName = value; } } FavoriteColorPtr getFavoriteColor() const { return myFavoriteColor; } void setFavoriteColor( const FavoriteColorPtr& value ) { if ( value ) { myFavoriteColor = value; } } bool getHasFavoriteColor() const { return myHasFavoriteColor; } void setHasFavoriteColot( const bool value ) { myHasFavoriteColor = value; } private: NamePtr myName; FavoriteColorPtr myFavoriteColor; bool myHasFavoriteColor; }; using Name = std::string; using NamePtr = std::shared_ptr<Name>; using FavoriteColor = std::string; using FavoriteColorPtr = std::shared_ptr<FavoriteColor>; /* Version 1: nullptr indicates FavoriteColor is absent, but Name will never be null because it is required */ class Person { public: Person() :myName( std::make_shared<Name>() ) ,myFavoriteColor() {} NamePtr getName() const { return myName; } void setName( const NamePtr& value ) { if( value ) { myName = value; } } FavoriteColorPtr getFavoriteColor() const { return myFavoriteColor; } void setFavoriteColor( const FavoriteColorPtr& value ) { myFavoriteColor = value; } private: NamePtr myName; FavoriteColorPtr myFavoriteColor; }; /* Version 2: FavoriteColor and Name can both be trusted to not be null, but you have to check HasFavoriteColor bool to see whether the optional data is legit */ class Person2 { public: Person2() :myName( std::make_shared<Name>() ) ,myFavoriteColor( std::make_shared<FavoriteColor>() ) {} NamePtr getName() const { return myName; } void setName( const NamePtr& value ) { if( value ) { myName = value; } } FavoriteColorPtr getFavoriteColor() const { return myFavoriteColor; } void setFavoriteColor( const FavoriteColorPtr& value ) { if ( value ) { myFavoriteColor = value; } } bool getHasFavoriteColor() const { return myHasFavoriteColor; } void setHasFavoriteColot( const bool value ) { myHasFavoriteColor = value; } private: NamePtr myName; FavoriteColorPtr myFavoriteColor; bool myHasFavoriteColor; }; <person> <name>Fred</name> <favorite-color>Blue</favorite-color> </person> using Name = std::string; using NamePtr = std::shared_ptr<Name>; using FavoriteColor = std::string; using FavoriteColorPtr = std::shared_ptr<FavoriteColor>; /* Version 1: nullptr indicates FavoriteColor is absent, but Name will never be null because it is required */ class Person { public: Person() :myName( std::make_shared<Name>() ) ,myFavoriteColor() {} NamePtr getName() const { return myName; } void setName( const NamePtr& value ) { if( value ) { myName = value; } } FavoriteColorPtr getFavoriteColor() const { return myFavoriteColor; } void setFavoriteColor( const FavoriteColorPtr& value ) { myFavoriteColor = value; } private: NamePtr myName; FavoriteColorPtr myFavoriteColor; }; /* Version 2: FavoriteColor and Name can both be trusted to not be null, but you have to check HasFavoriteColor bool to see whether the optional data is legit */ class Person2 { public: Person2() :myName( std::make_shared<Name>() ) ,myFavoriteColor( std::make_shared<FavoriteColor>() ) {} NamePtr getName() const { return myName; } void setName( const NamePtr& value ) { if( value ) { myName = value; } } FavoriteColorPtr getFavoriteColor() const { return myFavoriteColor; } void setFavoriteColor( const FavoriteColorPtr& value ) { if ( value ) { myFavoriteColor = value; } } bool getHasFavoriteColor() const { return myHasFavoriteColor; } void setHasFavoriteColot( const bool value ) { myHasFavoriteColor = value; } private: NamePtr myName; FavoriteColorPtr myFavoriteColor; bool myHasFavoriteColor; }; <person> <name>Fred</name> <favorite-color>Blue</favorite-color> </person> using Name = std::string; using NamePtr = std::shared_ptr<Name>; using FavoriteColor = std::string; using FavoriteColorPtr = std::shared_ptr<FavoriteColor>; /* Version 1: nullptr indicates FavoriteColor is absent, but Name will never be null because it is required */ class Person { public: Person() :myName( std::make_shared<Name>() ) ,myFavoriteColor() {} NamePtr getName() const { return myName; } void setName( const NamePtr& value ) { if( value ) { myName = value; } } FavoriteColorPtr getFavoriteColor() const { return myFavoriteColor; } void setFavoriteColor( const FavoriteColorPtr& value ) { myFavoriteColor = value; } private: NamePtr myName; FavoriteColorPtr myFavoriteColor; }; /* Version 2: FavoriteColor and Name can both be trusted to not be null, but you have to check HasFavoriteColor bool to see whether the optional data is legit */ class Person2 { public: Person2() :myName( std::make_shared<Name>() ) ,myFavoriteColor( std::make_shared<FavoriteColor>() ) {} NamePtr getName() const { return myName; } void setName( const NamePtr& value ) { if( value ) { myName = value; } } FavoriteColorPtr getFavoriteColor() const { return myFavoriteColor; } void setFavoriteColor( const FavoriteColorPtr& value ) { if ( value ) { myFavoriteColor = value; } } bool getHasFavoriteColor() const { return myHasFavoriteColor; } void setHasFavoriteColot( const bool value ) { myHasFavoriteColor = value; } private: NamePtr myName; FavoriteColorPtr myFavoriteColor; bool myHasFavoriteColor; };