Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math: improve diag_value constructors #77228

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

andrei8l
Copy link
Contributor

@andrei8l andrei8l commented Oct 21, 2024

Summary

None

Purpose of change

diag_value and diag_kwargs are a little awkward to use

Describe the solution

Add more constructors so you can use arithmetic values and string literals directly

Instead of

    diag_value type( std::string{ "ALL" } );

you can now write

    diag_value type( "ALL" );

Instead of

    diag_value type( static_cast<double>( PICKUP_RANGE ) );

you can now write

    diag_value type( PICKUP_RANGE );

Instead of

    diag_value str_val( std::string{} );
    diag_value art_val( 0.0 );

you can now write

    diag_value str_val;
    diag_value art_val;

and they are treated as zero/null values as needed.

You can also easily construct arrays now

    diag_value val( diag_array{ 1, 2, "three", var_info{} } );
Add a `kwarg_or()` helper function

Instead of

    diag_value type( std::string{ "ALL" } );
    if( kwargs.count( "type" ) != 0 ) {
        type = *kwargs.at( "type" );
    }

you can now write

    diag_value type = kwargs.kwarg_or( "type", "ALL" );

Works with empty values too

    diag_value type = kwargs.kwarg_or( "type" );

Describe alternatives you've considered

N/A

Testing

Existing test units

Additional context

GuardianDll take a look please and let me know if this is clear.

@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` new contributor json-styled JSON lint passed, label assigned by github actions labels Oct 21, 2024
@andrei8l andrei8l force-pushed the math-diag_value-qol branch 2 times, most recently from 3c4477a to 645ab48 Compare October 21, 2024 10:20
@github-actions github-actions bot added the astyled astyled PR, label is assigned by github actions label Oct 21, 2024
@GuardianDll
Copy link
Member

Yeah looks great for me

@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Oct 21, 2024
@andrei8l andrei8l marked this pull request as ready for review October 21, 2024 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions [C++] Changes (can be) made in C++. Previously named `Code` json-styled JSON lint passed, label assigned by github actions new contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants