What is the difference between std gcd and std gcd

0 votes
What’s the difference between this function and std::gcd?
Jun 10, 2022 in C++ by Nicholas
• 7,760 points
1,758 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, 2022 by Damon
• 4,960 points

Related Questions In C++

0 votes
0 answers

What is the difference between std::list<std::pair> and std::map in C++ STL?

What distinguishes std::list<std::pair> from std::map? Does the ...READ MORE

Aug 17, 2022 in C++ by Nicholas
• 7,760 points
616 views
0 votes
0 answers

What is the difference between ifstream, ofstream and fstream?

I stumbled discovered ifstream, ofstream, and fstream ...READ MORE

Jul 11, 2022 in C++ by Nicholas
• 7,760 points
787 views
0 votes
0 answers

What is the difference between Java and C++?

What is the difference between Java and ...READ MORE

Jul 22, 2022 in C++ by Nicholas
• 7,760 points
359 views
0 votes
0 answers

What is the difference between a concrete class and an abstract class?

I'm learning C++, but I'm having trouble ...READ MORE

Jul 26, 2022 in C++ by Nicholas
• 7,760 points
484 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, 2022 in C++ by Damon
• 4,960 points
2,923 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, 2022 in C++ by Damon
• 4,960 points
1,213 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, 2022 in C++ by Damon
• 4,960 points
1,764 views
0 votes
0 answers

C++ vector erase function not working properly

Here is the code I want to use to delete any entries with values more than 2 and fewer than 5. vector<int> myvector{3, 3, 3, 3, 3, 3, ...READ MORE

Jul 11, 2022 in C++ by Nicholas
• 7,760 points
606 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, 2022 in C++ by Damon
• 4,960 points
1,506 views
0 votes
1 answer

What is the difference between public, private, and protected inheritance in C++?

To begin answering that question, let me characterise member accessors in my own terms.  If you already know this, proceed to the section "next:". I'm aware of three types of accessors: public, protected, and private. Let: class Base { public: ...READ MORE

answered Jul 11, 2022 in C++ by Damon
• 4,960 points
747 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP