This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PacmanAlgo : public AgentImpl { | |
PacmanAlgo() | |
: AgentImpl(true) {} | |
virtual std::variant<Direction, Stop> GetAction(const WorldState& worldState, | |
const std::size_t id) override | |
{ | |
return Stop{}; | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename T> | |
T Square(const T& t) { | |
if constexpr (std::is_arithmetic<T>::value) { | |
return t * t; | |
} else { | |
return t.value * t.value; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int Square(const int& t) { | |
if (true) { | |
return t * t; | |
} else { | |
return t.value * t.value; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename T> | |
typename std::enable_if<std::is_arithmetic<T>::value, T>::type Square(const T& t) { | |
return t * t; | |
} | |
template<typename T> | |
typename std::enable_if<! std::is_arithmetic<T>::value, T>::type Square(const T& t) { | |
return t.value * t.value; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename T> | |
T Square(const T& t) { | |
if (std::is_arithmetic<T>::value) { | |
return t * t; | |
} else { | |
return t.value * t.value; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int integer_num = 5; | |
float floating_num = 5.0; | |
bool boolean = true; | |
Number<int> number_int(5); | |
auto res = Square(integer_num); // call int Square(int); | |
auto res2 = Square(floating_num); // call float Square(float); | |
auto res3 = Square(boolean); // call bool Square(bool); | |
auto res4 = Square(number_int); // call Number<int> Square(Number<int>); | |
// failed to compile, operator* not found |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename T> | |
T Square(const T& t) { | |
return t * t; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename T> | |
struct Number { | |
Number(const T& _val) : | |
value(_val) {} | |
T value; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
constexpr int Sum(const int a, const int b) { | |
return a + b; | |
} | |
int main(int argc, char **argv) { | |
constexpr int val = Sum(1, 2); | |
int var = 3; | |
int val2 = Sum(val, var); | |
return 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main(int argc, char **argv) { | |
int val = 3; | |
return 0; | |
} |