GithubHelp home page GithubHelp logo

Comments (4)

billyquith avatar billyquith commented on May 27, 2024

You can use PONDER_TYPE() for this purpose. You have to explicitly declare the type. There is no "auto" version. This macro works with any number of parameters.

I could perhaps make this more prominent in the docs.

from ponder.

lhamot avatar lhamot commented on May 27, 2024

Thank you for your answer.

With PONDER_TYPE(), I have to call it once by concrete type, isn't it?
For example:

PONDER_TYPE(TmplStruct<int>);
PONDER_TYPE(TmplStruct<short>);
PONDER_TYPE(TmplStruct<bool>);
// Have to explicitely call :
static void declare_TmplStruct(){
    ponder::Class::declare<TmplStruct<int> >()
        .property("field1", &TmplStruct<int>::field1);
    ponder::Class::declare<TmplStruct<short> >()
        .property("field1", &TmplStruct<short>::field1);
    ponder::Class::declare<TmplStruct<bool> >()
        .property("field1", &TmplStruct<bool>::field1);
}

Is there an other way to use PONDER_TYPE ?

What I am looking for is a way to avoid to declare each concrete types. Types which are referenced from a .property call could be automatically declared, I guess.
Anyway, I will look at the doc carefully.

from ponder.

billyquith avatar billyquith commented on May 27, 2024

Yes, as it stands you'd have to register once for each template instance, because each instance is a different type. I'm reluctant to add macros to the API to solve this because they would only solve one particular problem, and there are many ways in which templates could be used. Also, I don't really like macros because they make code opaque.

Another alternative:

PONDER_TYPE(TmplStruct<int>);
PONDER_TYPE(TmplStruct<short>);
PONDER_TYPE(TmplStruct<bool>);

template <typename T>
static void declare_TmplStruct() {
    ponder::Class::declare<TmplStruct<T> >()
        .property("field1", &TmplStruct<T>::field1);
}

static declare() {
	declare_TmplStruct<int>();
	declare_TmplStruct<short>();
	declare_TmplStruct<bool>();
}

Ideally I'd like to keep the API as simple as possible. I could add more examples like this to the docs.

from ponder.

billyquith avatar billyquith commented on May 27, 2024

I added an example in the docs. I'll close this unless there are further questions.

from ponder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.