emp-toolkit
swappable.h
Go to the documentation of this file.
1 #ifndef SWAPPABLE_H__
2 #define SWAPPABLE_H__
3 #include "bit.h"
4 class Bit;
5 
6 template<typename T>
7 class Swappable { public:
8  T If(const Bit & sel, const T& rhs) const {
9  return static_cast<const T*>(this)->select(sel, rhs);
10  }
11 };
12 template<typename T>
13 inline T If(const Bit & select, const T & o1, const T & o2) {
14  T res = o2;
15  return res.If(select, o1);
16 }
17 template<typename T>
18 inline void swap(const Bit & swap, T & o1, T & o2) {
19  T o = If(swap, o1, o2);
20  o = o ^ o2;
21  o1 = o ^ o1;
22  o2 = o ^ o2;
23 }
24 
25 #endif
Definition: swappable.h:7
void swap(const Bit &swap, T &o1, T &o2)
Definition: swappable.h:18
Definition: bit.h:8
T If(const Bit &sel, const T &rhs) const
Definition: swappable.h:8