第一篇博客


博客功能测试

代码高亮测试

  1. 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);
}
  1. 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) {
}

文章作者: Layton
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Layton !
  目录