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

Help wanted: error C2338: static_assert failed: 'Cannot format an argument. To make type T formattable, provide a formatter<T> specialization. #4093

Closed
chenboshuo opened this issue Oct 16, 2023 · 2 comments

Comments

@chenboshuo
Copy link

          > Most likely it is your bug, you are trying to format something that is not formattable. In any case, maintainers can't help without a repro.

I encounter this issue again, and this is my code

std::string debug_int_surf_surf(surf_surf_int* items, std::string name, const double kCurveParamStep) {
    std::string info;
    int id = 0;
    if(!items) {
        return name + ":no intersection\n";
    }
    while(items) {
        switch(items->int_type) {
            case surf_int_type::int_normal:  // 	Normal (usual) intersection.
                info += std::format("{} {} is a normal intersection\n", name, id);
                break;
            case surf_int_type::int_tangent:  // 	Tangent or coincident intersection, with normals in the same direction.
                info += std::format("{} {} is a tangent intersection\n", name, id);
                break;
            case surf_int_type::int_antitangent:  // Tangent or coincident intersection, with normals in opposite direction.
                info += std::format("{} {} is a antitangent intersection\n", name, id);
                break;
        }
        curve* curve = items->cur;
        if(!curve) {
            SPAposition p = items->end_term->term_pos;
            info += std::format("({} {}) point: ({},{},{})\n\tisolate point\n",  //
                                name,
                                id,                  //
                                p.x(), p.y(), p.z()  //
            );
            items = items->next;
            ++id;
            continue;
        }
        SPAinterval range = curve->param_range();
        double t;
        for(t = range.start_pt(); t <= range.end_pt(); t += kCurveParamStep) {
            SPAposition p;
            curve->eval(t, p);
            info += std::format(                              //
              "({} {}) point:({:.10f}, {:.10f}, {:.10f})\n",  //
              name, id, p.x(), p.y(), p.z());
        }
        t = range.end_pt();
        SPAposition p;
        curve->eval(t, p);
        info += std::format(                              //
          "({} {}) point:({:.10f}, {:.10f}, {:.10f})\n",  //
          name, id, p.x(), p.y(), p.z()                   //
        );

        if(name == "ACIS") {
            pcurve* p_curve = items->pcur2;
            if(p_curve) {
                SPAinterval param_range = p_curve->param_range();
                for(double t = param_range.start_pt(); t <= param_range.end_pt(); t += kCurveParamStep) {
                    SPApar_pos p = p_curve->eval_position(t);
                    info += std::format(            //
                      "(ACIS {}) param:({},{})\n",  //
                      id, p.u, p.v);
                }
            }
        }

        ++id;
        items = items->next;
    }
    return info;
}

This code is correct in VS 2019

Originally posted by @chenboshuo in #3860 (comment)

#3860 can't reopen

@chenboshuo chenboshuo changed the title error C2338: static_assert fa iled: 'Cannot format an argument. To make type T formattable, provide a formatter<T> specialization. See N4928 error C2338: static_assert failed: 'Cannot format an argument. To make type T formattable, provide a formatter<T> specialization. Oct 16, 2023
@chenboshuo chenboshuo changed the title error C2338: static_assert failed: 'Cannot format an argument. To make type T formattable, provide a formatter<T> specialization. Help wanted: error C2338: static_assert failed: 'Cannot format an argument. To make type T formattable, provide a formatter<T> specialization. Oct 16, 2023
@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented Oct 16, 2023

p.u and p.v are of type SPAparameter, which is implicitly convertible to double.

In short, SPAparameter is not formattable by default and a program-defined std::formatter specialization is needed.

Archaeological records

MSVC STL's historical dispatch mechanism used to accept some forms of implicit conversion to standard floating-point types, so SPAparameter was able to be formatted as double.

PR #3080 added the type checking you encountered and banned formatting unrecognized types.

Finally, the dispatch mechanism was completely rewritten by PR #3745 which implemented LWG-3631.

References

@chenboshuo
Copy link
Author

p.u and p.v are of type SPAparameter, which is implicitly convertible to double.

In short, SPAparameter is not formattable by default and a program-defined std::formatter specialization is needed.

Archaeological records

MSVC STL's historical dispatch mechanism used to accept some forms of implicit conversion to standard floating-point types, so SPAparameter was able to be formatted as double.

PR #3080 added the type checking you encountered and banned formatting unrecognized types.

Finally, the dispatch mechanism was completely rewritten by PR #3745 which implemented LWG-3631.

References

Thank you for your answer, I use static_cast<double> and it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants