Why acts std::chrono::duration::operator*= not like built-in *=?

Why acts std::chrono::duration::operator*= not like built-in *=?

As described in&nbsp;<a href="https://en.cppreference.com/w/cpp/chrono/duration/operator_arith3" target="_blank">std::chrono::duration::operator+=</a>&nbsp;the signature is

As described in std::chrono::duration::operator+= the signature is

duration& operator*=(const rep& rhs);

This makes me wonder. I would assume that a duration literal can be used like any other built-in, but it doesn't.

#include <chrono>
#include <iostream>

int main() { using namespace std::chrono_literals; auto m = 10min; m *= 1.5f; std::cout << " 150% of 10min: " << m.count() << "min" << std::endl;

int i = 10;
i *= 1.5f;
std::cout &lt;&lt; " 150% of 10: " &lt;&lt; i &lt;&lt; std::endl;

}

Output is

150% of 10min: 10min
150% of 10: 15

Why was the interface choosen that way? To my mind, an interface like

template<typename T> 
duration& operator*=(const T& rhs);

would yield more intuitive results.

EDIT: Thanks for your responses, I know that the implementation behaves that way and how I could handle it. My question is, why is it designed that way.

I would expect the conversion to int take place at the end of the operation. In the following example both operands get promoted to double before the multiplications happens. The intermediate result of 4.5 is converted to int afterwards, so that the result is 4.

int i = 3;
i *= 1.5;
assert(i == 4);

My expectation for std::duration would be that it behaves the same way.

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

C/C++ vs. Rust: A developer’s perspective

In this post, you'll see the difference between Rust and C/C++ in a developer’s perspective

Variable Introduction in C#[Bangla]

LIKE | COMMENT | SHARE | SUBSCRIBE A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C# has a speci...