Operator From()

About Monkey 2 Forums Monkey 2 Development Operator From()

This topic contains 7 replies, has 2 voices, and was last updated by  Mark Sibly 1 year, 5 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #11709

    nerobot
    Participant

    Is it a good idea to have From() operator (along with To())?
    I want to union similar conversions To/From in one place, it can be possible with From operator.
    Maybe I don’t know some limitation of that?

    Also I want to use From as co-operator for assignment operator.

    For example:

    In this example we have boxed int which behave like plain int type – and without creating new instance when assigning a value.

    PS. assignment operator will use From and just reassign variable to self if we don’t create instance inside of From.

    #11734

    Mark Sibly
    Keymaster

    I don’t like having 1001 ways to convert values as it can easily get too confusing how things work when the compiler does a ton of implicit/magic stuff behind your back. C++ is a bit like this – there’re copy ctors, assignments and cast operators (at least, probably more since c++11) all of which can result in type conversions but it’s not always obvious which one gets called or even when.

    So the monkey2 equivalent might be: if ‘operator from’ WAS supported, and a dst type implemented ‘operator from’ and a src type implemented ‘operator to’, which would get used when converting from src type to dst type?

    IMO, operator to plus type extensions allows you to do pretty much anything without everything getting too confusing. If there’s something you can’t do this way, let me know and we can try to come up with a solution.

    For example, it allows me use std.geom types like Vec3f with assimp and bullet and have them automatically convert correctly from the native assimp/bullet geom types like aiVector3D.

    And there is no overloadable assignment operator in monkey2 (or copy ctor).

    #11736

    nerobot
    Participant

    The truth is, I don’t want to have such magic in monkey2.

    I agree – operator To + extensions = powerful coding.

    So the monkey2 equivalent might be: if ‘operator from’ WAS supported, and a dst type implemented ‘operator from’ and a src type implemented ‘operator to’, which would get used when converting from src type to dst type?

    Left-sided vars have a bigger priority, I think…

    If there’s something you can’t do this way, let me know and we can try to come up with a solution.

    I’m triyng to do observable variables – sort of plain values wrapper which would notify listeners about value changing.

    And I want to use this wrapper as a plain type, but I can’t catch value assignment without overriding of assign operator.

    Variant type have a magic with value assigning – we can assign anything.

    I want to do something like that but with strong types checking via generics.

    My example:

    #11750

    Mark Sibly
    Keymaster

    No, I will not  supporting assignment overloading in the near future, if ever.

    There are a lot of complications involved with assignment overloading which I’m not going to go into right now (email me if you want to discuss further…) but that I don’t want to weigh the language down with.

    #11755

    nerobot
    Participant

    No, I will not supporting assignment overloading in the near future, if ever.

    I agree, and I never used it in c++.

    Any ideas how to get what I want?

    My idea is to have special base class with Assigned event. So we can’t break anything by overloading but can react on assignment:

    Maybe this class will extends Variant but with generic type.

    And usage:

    #11757

    Mark Sibly
    Keymaster

    Any ideas how to get what I want?

    I’m not actually sure what you want.

    If you want a function to be called when a value is modified, you’ll need a ‘Set’ style method for assignments because, well, there is no assignment overloading. This is pretty trivial to implement though so I suspect you mean something else (or that you really *do* want assignment overloading!).

    #11759

    nerobot
    Participant

    If you want a function to be called when a value is modified, you’ll need a ‘Set’ style method for assignments

    Yes, I want this! But don’t want to use Set or properties.:)

    Saying about Class Assignable<T> above I meant to have it as a core type of monkey2 like a Variant is.

    Variant have an assignment magic on a c++ side. I need right the same plus event Assigned to be able to react on value changes.

    I know that this is very specific thing, but maybe it sounds useful not for me only.

    #11764

    Mark Sibly
    Keymaster

    >Yes, I want this! But don’t want to use Set or properties.:)

    So you do want assignment overloading…as I’ve said above, this is not happening sorry!

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.