Absence of function overloads of the function div for unsigned integer numbers.

45 views
Skip to first unread message

Vlad from Moscow

unread,
Jun 20, 2018, 10:15:44 AM6/20/18
to ISO C++ Standard - Discussion
When I was doing an assignment (See Forming the smallest number. Though the topic is written in Russian nevertheless it contains a reference to the original question asked at Stackoverflow) I wondered why the function div does not contain overloads for unsigned integer types.  I think it would be logically consistent if there were overloads for types unsigned int, unsigned long int, and unsigned long long int.

Vlad from Moscow

unread,
Jun 20, 2018, 10:59:58 AM6/20/18
to ISO C++ Standard - Discussion
Can the function will be appended with the following declarations

template <typename T>
struct udiv_t
{
    T quot
;
    T rem
;
};


template <typename T>
udiv_t
<T> div( T numer, T denom )
{
   
return { numer / denom, numer % denom };
}


среда, 20 июня 2018 г., 17:15:44 UTC+3 пользователь Vlad from Moscow написал:

Bo Persson

unread,
Jun 20, 2018, 1:45:07 PM6/20/18
to std-dis...@isocpp.org
On 2018-06-20 16:15, 'Vlad from Moscow' via ISO C++ Standard -
Discussion wrote:
> When I was doing an assignment (See Forming the smallest number
> <http://cpp.forum24.ru/?1-1-0-00000091-000-0-0-1529414277>. Though the
> topic is written in Russian nevertheless it contains a reference to the
> original question asked at Stackoverflow) I wondered why the function
> *div *does not contain overloads for unsigned integer types.  I think it
> would be logically consistent if there were overloads for types unsigned
> int, unsigned long int, and unsigned long long int.
>

There is no real reason anymore for this kind of low level optimization.
Modern compilers will recognize if you compute both quotient and
remainder, and (on an x86 at least) use a single instruction to compute
both values.


Bo Persson


Vlad from Moscow

unread,
Jun 21, 2018, 8:44:20 AM6/21/18
to ISO C++ Standard - Discussion, b...@gmb.dk
But it provides a common interface. And that is important.

среда, 20 июня 2018 г., 20:45:07 UTC+3 пользователь Bo Persson написал:
Reply all
Reply to author
Forward
0 new messages