Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Extend tuple features (e.g. join) to tuple-like objects #4226

@correaa

Description

@correaa

For some technical reasons I had to replicate the functionality of std::tuple in my library. (see here: https://github.com/correaa/boost-multi?tab=readme-ov-file#formatting-fmt-pretty-printing)

I would be nice that the features in fmt would work on any type that has std::get<N>, std::tuple_size, etc. in their interface.
That is, if a type is tuple like then it could be printed as a tuple.

(This will also work on any class for which structured binding is implemented).

int main() {

    std::tuple<int, int> t1(1, 2);
    fmt::print( "{}", fmt::join(t1, "x") );  // prints 1 x 2

    my_tuple<int, int> t2(1, 2);
    fmt::print( "{}", fmt::join(t2, "x") );  // doesn't work now
}

Here it is a godbolt example:

https://godbolt.org/z/Gof6f4oaE

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions