博客功能测试
代码高亮测试
- C++ 代码:
template <class TFactory>
auto REQUIRES(m_mutex) getFactory(const std::string& id) const ->
typename FactoryDetails::get_interface_const_ref<TFactory>::type
{
tComponentContItr componentPtr = findComponentFactory<TFactory>();
if (componentPtr != m_componentCont.end())
{
auto factory = componentPtr->second.find(id);
if (factory != componentPtr->second.end())
{
using tInterface =
typename FactoryDetails::get_interface<TFactory>::type;
return *static_cast<tInterface*>(factory->second->getPtr());
}
}
throw FactoryNotRegisteredEx(typeid(TFactory).name(), id);
}
- Rust 代码:
impl<T> Cacher<T>
where
T: Fn(u32) -> u32,
{
fn new(calculation: T) -> Cacher<T> {
Cacher {
calculation,
value: None,
}
}
fn value(&mut self, arg: u32) -> u32 {
match self.value {
Some(v) => v,
None => {
let v = (self.calculation)(arg);
self.value = Some(v);
v
}
}
}
}
fn main() {
let simulated_user_specified_value = 10;
let simulated_random_number = 7;
generate_workout(simulated_user_specified_value, simulated_random_number);
}
fn generate_workout(intensity: u32, random_number: u32) {
}