[odb-users] Embed operator==(const DBO& other) yields compilation error when using odb::lazy_shared_ptr

Vassilios Kountouriotis b.kountouriotis at gmail.com
Wed Sep 20 08:26:38 EDT 2017


Hello. If I have:

#pragma db object table("Game")
class DB_Game
{
    public:
        friend class odb::access;

        std::string &primaryKey() { return ID; }

        static std::string primaryKeyName() { return "ID"; }

        #pragma db id type("CHAR(36) BINARY") not_null
        std::string ID;

        #pragma db not_null
        odb::lazy_shared_ptr<DB_GameType> GameTypeID;

        #pragma db type("VARCHAR(255)") not_null
        std::string Name;

        #pragma db type("VARCHAR(512)") null
        odb::nullable<std::string> Description;

        #pragma db type("VARCHAR(255)") null
        odb::nullable<std::string> GameEngine;

        #pragma db type("TINYINT(1)") not_null default(1)
        bool Enabled { 1 } ;

        #pragma db index("gameCategory_idx") member(GameTypeID)

        bool operator==(const DB_Game& other) {
            auto sp_GameTypeID = other.GameTypeID.load();
            auto spo_GameTypeID = GameTypeID.load();
            auto GameTypeID_eq = sp_GameTypeID == spo_GameTypeID;
            auto GameTypeID_bnn = (sp_GameTypeID) && (spo_GameTypeID);
            bool GameTypeID_check = (GameTypeID_eq && sp_GameTypeID ==
nullptr) || (GameTypeID_bnn && sp_GameTypeID->primaryKey() ==
spo_GameTypeID->primaryKey());

            return ( other.ID == ID &&
                     GameTypeID_check &&
                     other.Name == Name &&
                     *other.Description == *Description &&
                     *other.GameEngine == *GameEngine &&
                     other.Enabled == Enabled );
        }
};

yields

/usr/libexec/odb/x86_64-linux-gnu/include/odb/lazy-ptr.ixx:1153:
error: no match for ‘operator=’ (operand types are
‘std::shared_ptr<DB_GameType>’ and
‘odb::object_traits<DB_GameType>::pointer_type {aka DB_GameType*}’)
       p_ = i_.template load<T> (true); // Reset id.
          ^

It seems like it ignores the shared_ptr pointer type.

I compile with:

odb --schema-name iRGS --std c++11 -d mysql --default-pointer
std::shared_ptr --generate-schema --generate-query --schema-format
separate --at-once --profile boost/date-time
-I/home/yourself/projects/rgs/3rd_party/boost/include/  --output-dir
iRGS/ --changelog-dir iRGS/ --fkeys-deferrable-mode not_deferrable
--input-name "iRGS" iRGS/DB_*.h

If, on the other hand, I use plain pointers, everything compiles fine.

What can I do?

Thanks.
-- 
Vassilios Kountouriotis



More information about the odb-users mailing list