title: How does the "lazy evaluation" of Boost Log's trivial loggers work?
body: <p>[<em>Follows up <a href="https://stackoverflow.com/a/50345102/9305398">Check boost::log filter explicitly?
  </a></em>]</p>
  
  <p>The following example uses the trivial logger from <a href="https://www.boost.org/doc/libs/master/libs/log/doc/html/index.html" rel="nofollow noreferrer">Boost Log</a>. It outputs <code>1</code>, showing that <code>expensive()</code> is only called once. How does it work? Why is <code>expensive()</code> not called?</p>
  
  <p><strong><kbd><a href="http://coliru.stacked-crooked.com/a/fa0a761fa43b0119" rel="nofollow noreferrer">Live On Coliru</a></kbd></strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  
  #include &lt;boost/log/expressions.hpp&gt;
  #include &lt;boost/log/trivial.hpp&gt;
  
  int count = 0;
  
  int expensive()
  {
      return ++count;
  }
  
  int main()
  {
      boost::log::core::get()-&gt;set_filter(
          boost::log::trivial::severity &gt;= boost::log::trivial::warning
      );
  
      BOOST_LOG_TRIVIAL(error) &lt;&lt; expensive();
      BOOST_LOG_TRIVIAL(info) &lt;&lt; expensive();
  
      std::cout &lt;&lt; count &lt;&lt; '\n';
  
      return 0;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>[2018-05-21 14:33:47.327507] [0x00007eff37aa1740] [error]   1
  1
  </code></pre>