Skip to content

Cannot use Profilers #7

@FabianSchuetze

Description

@FabianSchuetze

The following fails to compile:

#include "perf"
int main() { perf::profiler local_profiler{perf::stat::tsc}; }

With error message (clang 21):

main.cpp:2:29: error: no viable constructor or deduction guide for
      deduction of template arguments of 'perf::profiler'
    2 | int main() { perf::profiler local_profiler{perf::stat::tsc}; }
      |                             ^
./perf.hpp:3357:10: note: candidate template ignored: could not match
      'profiler' against 'perf::fixed_named'
 3357 |   struct profiler {
      |          ^
./perf.hpp:3357:10: note: implicit deduction guide declared as 'template
      <class ...TProfilers> requires ((profiler_like<TProfilers> && requires
      (TProfilers profilers) { profilers[]; }) && ...) profiler(profiler<TProfilers...>) ->
      profiler<TProfilers...>'
./perf.hpp:3358:24: note: candidate template ignored: constraints not
      satisfied [with TProfilers = <const fixed_named<"stat.tsc[ns]", struct rdtsc>>]
 3358 |     constexpr explicit profiler(TProfilers&... profilers)
      |                        ^
./perf.hpp:3355:16: note: because 'const
      perf::fixed_named<basic_fixed_string<char, 13UL>{"stat.tsc[ns]"}, perf::stat::rdtsc>'
      does not satisfy 'profiler_like'
 3355 |     requires ((profiler_like<TProfilers> and
      |                ^
./perf.hpp:3350:5: note: because 't.start()' would be invalid: 'this'
      argument to member function 'start' has type 'const
      perf::fixed_named<basic_fixed_string<char, 13UL>{"stat.tsc[ns]"}, perf::stat::rdtsc>',
      but function is not marked const
 3350 |     t.start();
      |     ^
./perf.hpp:3356:48: note: and 'profilers[]' would be invalid: type 'const
      perf::fixed_named<basic_fixed_string<char, 13UL>{"stat.tsc[ns]"}, perf::stat::rdtsc>'
      does not provide a subscript operator
 3356 |     requires (TProfilers profilers) { profilers[]; }) and ...)
      |                                                ^
./perf.hpp:3358:24: note: implicit deduction guide declared as 'template
      <class ...TProfilers> requires ((profiler_like<TProfilers> && requires
      (TProfilers profilers) { profilers[]; }) && ...) explicit profiler(TProfilers
      &...profilers) -> profiler<TProfilers...> requires ((profiler_like<TProfilers> &&
      requires (TProfilers profilers) { profilers[]; }) && ...)'
 3358 |     constexpr explicit profiler(TProfilers&... profilers)
      |                        ^
1 error generated.

Mostly because operator[] isn't defined for tsc and also because start/stop isn't const. With mutable and const, I can get around the error of start/stop not being const, but I'm not sure what to do for operator[].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions