Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,885 questions

51,811 answers

573 users

How to use variadic function template to check for pair compare in a set of number with C++

1 Answer

0 votes
#include <iostream>

template<typename T>
bool PairCompare(T a, T b) {
    return a == b;
}

template<typename T, typename... Args>
bool PairCompare(T a, T b, Args... args) {
  return a == b && PairCompare(args...);
}

int main() {
    std::cout << PairCompare(3, 3, 7.8, 7.8, 99, 99, 0.17, 0.17) << "\n";
    std::cout << PairCompare(3, 3, 7.8, 7.8, 99, 99, 5, 6) << "\n";
}




/*
run:

1
0

*/

 



answered Dec 7, 2022 by avibootz

Related questions

2 answers 120 views
1 answer 90 views
90 views asked Dec 6, 2022 by avibootz
1 answer 182 views
1 answer 110 views
1 answer 102 views
1 answer 106 views
1 answer 162 views
...