Skip to main content
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

Just a few comments on this one.

Only specify default parameters in the declaration

The constructor is already declared to have a default parameter value, so the implementation should omit the default value.

Remove state from the object

I don't see much point in using the state of the object only to ignore a user request, but that appears to be the sole use of the started_ member variable. If I happen to call start more than once, all calls after the first are simply ignored. For an alternative approach, see this stopwatch templatestopwatch template.

Simplify the interface

It would be nice to be able to use the template like this:

std::cout << cr::stopwatch<>::measure(test) << '\n';

Unfortunately, that won't compile, and the user is required to tack on .count() to make this work. One cheesy but effective way to do this might be by use of a macro:

#define measure(x) #x << ": " << cr::stopwatch<>::measure(x).count() << " ms"

Now it can be used:

std::cout << measure(test) << '\n';

Sample output:

test: 191 ms

Just a few comments on this one.

Only specify default parameters in the declaration

The constructor is already declared to have a default parameter value, so the implementation should omit the default value.

Remove state from the object

I don't see much point in using the state of the object only to ignore a user request, but that appears to be the sole use of the started_ member variable. If I happen to call start more than once, all calls after the first are simply ignored. For an alternative approach, see this stopwatch template.

Simplify the interface

It would be nice to be able to use the template like this:

std::cout << cr::stopwatch<>::measure(test) << '\n';

Unfortunately, that won't compile, and the user is required to tack on .count() to make this work. One cheesy but effective way to do this might be by use of a macro:

#define measure(x) #x << ": " << cr::stopwatch<>::measure(x).count() << " ms"

Now it can be used:

std::cout << measure(test) << '\n';

Sample output:

test: 191 ms

Just a few comments on this one.

Only specify default parameters in the declaration

The constructor is already declared to have a default parameter value, so the implementation should omit the default value.

Remove state from the object

I don't see much point in using the state of the object only to ignore a user request, but that appears to be the sole use of the started_ member variable. If I happen to call start more than once, all calls after the first are simply ignored. For an alternative approach, see this stopwatch template.

Simplify the interface

It would be nice to be able to use the template like this:

std::cout << cr::stopwatch<>::measure(test) << '\n';

Unfortunately, that won't compile, and the user is required to tack on .count() to make this work. One cheesy but effective way to do this might be by use of a macro:

#define measure(x) #x << ": " << cr::stopwatch<>::measure(x).count() << " ms"

Now it can be used:

std::cout << measure(test) << '\n';

Sample output:

test: 191 ms

added cheesy macro
Source Link
Edward
  • 67.2k
  • 4
  • 120
  • 284

Just a few comments on this one.

Only specify default parameters in the declaration

The constructor is already declared to have a default parameter value, so the implementation should omit the default value.

Remove state from the object

I don't see much point in using the state of the object only to ignore a user request, but that appears to be the sole use of the started_ member variable. If I happen to call start more than once, all calls after the first are simply ignored. For an alternative approach, see this stopwatch template.

Simplify the interface

It would be nice to be able to use the template like this:

std::cout << cr::stopwatch<>::measure(test) << '\n';

Unfortunately, that won't compile, and the user is required to tack on .count() to make this work. One cheesy but effective way to do this might be by use of a macro:

#define measure(x) #x << ": " << cr::stopwatch<>::measure(x).count() << " ms"

Now it can be used:

std::cout << measure(test) << '\n';

Sample output:

test: 191 ms

Just a few comments on this one.

Only specify default parameters in the declaration

The constructor is already declared to have a default parameter value, so the implementation should omit the default value.

Remove state from the object

I don't see much point in using the state of the object only to ignore a user request, but that appears to be the sole use of the started_ member variable. If I happen to call start more than once, all calls after the first are simply ignored. For an alternative approach, see this stopwatch template.

Simplify the interface

It would be nice to be able to use the template like this:

std::cout << cr::stopwatch<>::measure(test) << '\n';

Unfortunately, that won't compile, and the user is required to tack on .count() to make this work.

Just a few comments on this one.

Only specify default parameters in the declaration

The constructor is already declared to have a default parameter value, so the implementation should omit the default value.

Remove state from the object

I don't see much point in using the state of the object only to ignore a user request, but that appears to be the sole use of the started_ member variable. If I happen to call start more than once, all calls after the first are simply ignored. For an alternative approach, see this stopwatch template.

Simplify the interface

It would be nice to be able to use the template like this:

std::cout << cr::stopwatch<>::measure(test) << '\n';

Unfortunately, that won't compile, and the user is required to tack on .count() to make this work. One cheesy but effective way to do this might be by use of a macro:

#define measure(x) #x << ": " << cr::stopwatch<>::measure(x).count() << " ms"

Now it can be used:

std::cout << measure(test) << '\n';

Sample output:

test: 191 ms

Post Undeleted by Edward
posted complete answer
Source Link
Edward
  • 67.2k
  • 4
  • 120
  • 284

Just a few comments on this one.

Only specify default parameters in the declaration

The constructor is already declared to have a default parameter value, so the implementation should omit the default value.

Remove state from the object

I don't see much point in using the state of the object only to ignore a user request, but that appears to be the sole use of the started_ member variable. If I happen to call start more than once, all calls after the first are simply ignored. For an alternative approach, see this stopwatch template.

Simplify the interface

It would be nice to be able to use the template like this:

std::cout << cr::stopwatch<>::measure(test) << '\n';

Unfortunately, that won't compile, and the user is required to tack on .count() to make this work.

Just a few comments on this one.

Only specify default parameters in the declaration

The

Just a few comments on this one.

Only specify default parameters in the declaration

The constructor is already declared to have a default parameter value, so the implementation should omit the default value.

Remove state from the object

I don't see much point in using the state of the object only to ignore a user request, but that appears to be the sole use of the started_ member variable. If I happen to call start more than once, all calls after the first are simply ignored. For an alternative approach, see this stopwatch template.

Simplify the interface

It would be nice to be able to use the template like this:

std::cout << cr::stopwatch<>::measure(test) << '\n';

Unfortunately, that won't compile, and the user is required to tack on .count() to make this work.

Post Deleted by Edward
Source Link
Edward
  • 67.2k
  • 4
  • 120
  • 284
Loading