X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FLazy.h;h=f1d81cad5143286f9f6cfbac7555c0a96a443c85;hb=d7b6ad4972b288f90bf57d7597103c44c244decd;hp=786f51c6ac0e9b3807b77b6430f25aeb8509dd6e;hpb=ed8c80a0e0988e4ce687f51ca832a00e4a6b7930;p=folly.git diff --git a/folly/Lazy.h b/folly/Lazy.h index 786f51c6..f1d81cad 100644 --- a/folly/Lazy.h +++ b/folly/Lazy.h @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2013-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ #pragma once -#include #include +#include #include @@ -86,7 +86,7 @@ namespace folly { namespace detail { -template +template struct Lazy { typedef typename std::result_of::type result_type; @@ -107,20 +107,22 @@ struct Lazy { } result_type& operator()() { - if (!value_) value_ = func_(); + if (!value_) { + value_ = func_(); + } return *value_; } -private: + private: Optional value_; Func func_; }; -} +} // namespace detail ////////////////////////////////////////////////////////////////////// -template +template detail::Lazy::type> lazy(Func&& fun) { return detail::Lazy::type>( @@ -130,4 +132,4 @@ lazy(Func&& fun) { ////////////////////////////////////////////////////////////////////// -} +} // namespace folly