Repository: ggerganov/llama.cpp
File: common/jinja/value.h (C/C++)

Code before:
        ss << "]";
        return ss.str();
    }
    virtual bool as_bool() const override {
        return !val_arr.empty();
    }
    virtual const func_builtins & get_builtins() const override;
};
using value_array = std::shared_ptr<value_array_t>;


struct value_object_t : public value_t {
    value_object_t() = default;
    value_object_t(value & v) {
        val_obj = v->val_obj;
    }
    value_object_t(const std::map<std::string, value> & obj) {
        for (const auto & pair : obj) {
            val_obj.insert(pair.first, pair.second);
        }
    }
    void insert(const std::string & key, const value & val) {
        val_obj.insert(key, val);
    }
    virtual std::string type() const override { return "Object"; }
    virtual const std::vector<std::pair<std::string, value>> & as_object() const override { return val_obj.ordered; }
    virtual bool as_bool() const override {
        return !val_obj.unordered.empty();
    }
    virtual const func_builtins & get_builtins() const override;
};
using value_object = std::shared_ptr<value_object_t>;

//
// null and undefined types
//

struct value_none_t : public value_t {
    virtual std::string type() const override { return "None"; }
    virtual bool is_none() const override { return true; }
    virtual bool as_bool() const override { return false; }
    virtual std::string as_repr() const override { return type(); }
    virtual const func_builtins & get_builtins() const override;
};
using value_none = std::shared_ptr<value_none_t>;


struct value_undefined_t : public value_t {
    std::string hint; // for debugging, to indicate where undefined came from
    value_undefined_t(const std::string & h = "") : hint(h) {}
    virtual std::string type() const override { return hint.empty() ? "Undefined" : "Undefined (hint: '" + hint + "')"; }

Review comment (suggestion):
I think this should be renamed to `as_ordered_object()`

Also, `value_to_json_internal` and `dictsort` are currently reading `val->val_obj.ordered` directly, it should be changed to use `as_ordered_object()`

Code after:
        ss << "]";
        return ss.str();
    }
    virtual bool as_bool() const override {
        return !val_arr.empty();
    }
    virtual const func_builtins & get_builtins() const override;
};
using value_array = std::shared_ptr<value_array_t>;


struct value_object_t : public value_t {
    value_object_t() = default;
    value_object_t(value & v) {
        val_obj = v->val_obj;
    }
    value_object_t(const std::map<std::string, value> & obj) {
        for (const auto & pair : obj) {
            val_obj.insert(pair.first, pair.second);
        }
    }
    value_object_t(const std::vector<std::pair<std::string, value>> & obj) {
        for (const auto & pair : obj) {
            val_obj.insert(pair.first, pair.second);
        }
    }
    void insert(const std::string & key, const value & val) {
        val_obj.insert(key, val);
    }
    virtual std::string type() const override { return "Object"; }
    virtual const std::vector<std::pair<std::string, value>> & as_ordered_object() const override { return val_obj.ordered; }
    virtual bool as_bool() const override {
        return !val_obj.unordered.empty();
    }
    virtual const func_builtins & get_builtins() const override;
};
using value_object = std::shared_ptr<value_object_t>;

//
// null and undefined types
//

struct value_none_t : public value_t {
    virtual std::string type() const override { return "None"; }
    virtual bool is_none() const override { return true; }
    virtual bool as_bool() const override { return false; }
    virtual std::string as_repr() const override { return type(); }
    virtual const func_builtins & get_builtins() const override;
};
using value_none = std::shared_ptr<value_none_t>;