What is the difference between std gcd and std gcd

0 votes
What’s the difference between this function and std::gcd?
Jun 10 in C++ by Nicholas
• 2,520 points
20 views

1 answer to this question.

0 votes
I done some research about this. The __gcd function seems to be a private auxiliary function created in the libstdc++ implementation of the algorithm> header's libstdc++ implementation (line 1503). Only the std::rotate function uses it internally (line 1610). It was (likely) never meant to be used outside of the library's implementation. Attempting to use this method with a compiler other than g++ isn't guaranteed to work because it's special to libstdc++. In this respect, the std:: gcd function can be thought of as a (poorly described) internal aid that is only available with certain C++ compilers.

A now-deleted query here originally alerted me to the existence of __gcd, which asked why it handled negative inputs inconsistently. Because the libstdc++ implementation only utilises it when the inputs are nonnegative, it turns out it wasn't actually built to handle negative values. It's one of the drawbacks of utilising an internal helper method that isn't documented!)

std::gcd, on the other hand, is a standard C++ library function added in C++17. This implies that any C++17-compliant compiler will support std::gcd, therefore if you have a C++17-compliant compiler, you should use this option.

You may easily implement your own version GCD function in C++14 or lower. Euclid's algorithm is simple to implement and runs exceedingly rapidly.
answered Jun 10 by Damon
• 4,240 points

Related Questions In C++

0 votes
0 answers

What is the easiest way to initialize a std::vector with hardcoded elements?

I can make an array and initialise&nb ...READ MORE

6 days ago in C++ by Nicholas
• 2,520 points
10 views
0 votes
1 answer

why are copy constructors needed and what are the cases where they are very helpful?

A copy constructor is a member function ...READ MORE

answered May 31 in C++ by Damon
• 4,240 points
36 views
0 votes
1 answer

What data structure is inside std::map in C++?

An associative container is std::map. The standard's ...READ MORE

answered May 31 in C++ by Damon
• 4,240 points
22 views
0 votes
0 answers

What is the C++ function to raise a number to a power?

What's the best way to raise a n ...READ MORE

Jun 1 in C++ by Nicholas
• 2,520 points
18 views
0 votes
1 answer

Why would anyone use set instead of unordered_set?

Unordered sets must compensate for their O(1) ...READ MORE

answered Jun 1 in C++ by Damon
• 4,240 points
39 views
0 votes
1 answer

Lower and Upper Bound in case of Decreasing/Non-ascending vector

Both std::lower bound and std::upper bound must have an increasing (non-decreasing) order as their objective. By giving a comparator as the 4th parameter of the functions, you may modify the meaning of "growing." To work with descending vectors, use std::greater. #include<iostream> #include<vector> #include<algorithm> #include<functional> using namespace std; int main() { ...READ MORE

answered Jun 14 in C++ by Damon
• 4,240 points
6 views
0 votes
1 answer

How do i apply lower_bound to a range of unsorted vector elements?

What's the point of sorting your array? ...READ MORE

answered Jun 15 in C++ by Damon
• 4,240 points
16 views
0 votes
1 answer

setuptools: build shared libary from C++ code, then build Cython wrapper linked to shared libary

There is a seemingly undocumented feature of setup that ...READ MORE

answered Sep 11, 2018 in Python by Priyaj
• 58,080 points
191 views
0 votes
1 answer

C++ code file extension? What is the difference between .cc and .cpp [closed]

GNU GCC recognizes all of the following ...READ MORE

answered Jun 21 in C++ by Damon
• 4,240 points
5 views
0 votes
1 answer

What is the name of the "<<" and ">>" operators? [duplicate]

According to cplusplus.com's documentation: This operator (<<) applied to ...READ MORE

answered Jun 20 in C++ by Damon
• 4,240 points
8 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP