Skip to content

Default values for ports with generic types #580

Closed
@OPerepadia

Description

@OPerepadia

I would like to set default values for ports with generic types.

This code from tutorial 3 compiles and works as expected:

return {InputPort<Position2D>("target", description)};

But this one produces an error - no matching function for call to ‘to_string(BT::Position2D&)’

return {InputPort<Position2D>("target", {1.0, 2.0}, description)};

Is this not implemented or am I missing something in my code?

Activity

OPerepadia

OPerepadia commented on Jun 9, 2023

@OPerepadia
ContributorAuthor

Solved. I added toStr function so it knows how to convert this type back to string, and now it compiles and works as expected.

template <>
inline std::string toStr<Position2D>(Position2D value) {
    std::ostringstream ss;
    ss << value.x << ";" << value.y;
    return ss.str();
}
OPerepadia

OPerepadia commented on Jun 9, 2023

@OPerepadia
ContributorAuthor

@facontidavide Maybe we should include this function in the tutorial 03?

facontidavide

facontidavide commented on Jun 9, 2023

@facontidavide
Collaborator

interesting, I would say that this is almost a bug. Let me add a more useful error message

facontidavide

facontidavide commented on Jun 9, 2023

@facontidavide
Collaborator

changed the message error to be more useful

facontidavide

facontidavide commented on Jun 10, 2023

@facontidavide
Collaborator

Sooooo...
The solution to this problem was finally more complicated that I expected.

I have a new branch v4.3, where I implemented a considerable improvement of the default value for custom types.

You may try that, if you want.

added a commit that references this issue on Feb 12, 2024

Fix BehaviorTree#580 : more informative error when not specializing B…

77c0571
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Default values for ports with generic types · Issue #580 · BehaviorTree/BehaviorTree.CPP