Skip to content

Instantly share code, notes, and snippets.

View 2catycm's full-sized avatar
💭
happy

Ye Canming 叶璨铭 2catycm

💭
happy
  • Tsinghua University 清华大学
  • Shenzhen, China 中国深圳
  • 19:08 (UTC +08:00)
View GitHub Profile
@2catycm
2catycm / gist:7c0e8797921b2ba19651d157a45c40f4
Last active January 29, 2024 16:17
限定lambda函数的类型
#include <array>
#include <type_traits>
template<typename F>
auto foo(F f) -> typename std::enable_if<
std::is_same<decltype(f(std::declval<int>(), std::declval<int>())), std::array<int, 2>>::value,
std::array<int, 2>
>::type
{
return f(1, 2);
@2catycm
2catycm / gist:e3f74727094f5628a36f345775e6efb3
Last active January 26, 2024 05:09
Rust:为其他库里面的trait实现新的类型应该怎么处理
use validator::Validate;
impl<T: Validate> Validate for swagger::Nullable<T> {
fn validate(&self) -> Result<(), validator::ValidationErrors> {
match self {
swagger::Nullable::Value(v) => v.validate(),
swagger::Nullable::Null => Ok(()),
}
}
}