title: How to call a parameterless function using boost::json::value
body: <p>I'm modifying from <a href="https://www.boost.org/doc/libs/develop/libs/describe/doc/html/describe.html#:%7E:text=4%205%206-,Automatic%25%2020JSON%20RPC,-This%20example%20defines" rel="nofollow noreferrer">here</a> code:</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;boost/describe.hpp&gt;
  #include &lt;boost/mp11.hpp&gt;
  #include &lt;boost/json.hpp&gt;
  #include &lt;boost/type_traits.hpp&gt;
  #include &lt;boost/utility/string_view.hpp&gt;
  #include &lt;stdexcept&gt;
  #include &lt;string&gt;
  #include&lt;iostream&gt;
  template&lt;class C1, class C2, class R, class... A, std::size_t... I&gt;
  boost::json::value
  call_impl_(C1&amp; c1, R(C2::* pmf)(A...), boost::json::array const&amp; args,
    std::index_sequence&lt;I...&gt;)
  {
    return boost::json::value_from(
      (c1.*pmf)(
        boost::json::value_to&lt; boost::remove_cv_ref_t&lt;A&gt; &gt;(args[I])...));
  }
  
  template&lt;class C1, class C2, class R, class... A&gt;
  boost::json::value
  call_impl(C1&amp; c1, R(C2::* pmf)(A...), boost::json::array const&amp; args)
  {
    if (args.size() != sizeof...(A))
    {
      throw std::invalid_argument(&quot;Invalid number of arguments&quot;);
    }
  
    return call_impl_(c1, pmf, args, std::index_sequence_for&lt;A...&gt;());
  }
  
  template&lt;class C&gt;
  boost::json::value
  call(C&amp; c, boost::string_view method, boost::json::value const&amp; args)
  {
    using Fd = boost::describe::describe_members&lt;C,
      boost::describe::mod_public | boost::describe::mod_function&gt;;
  
    bool found = false;
    boost::json::value result;
  
    boost::mp11::mp_for_each&lt;Fd&gt;([&amp;](auto D) {
  
      if (!found &amp;&amp; method == D.name)
      {
        result = call_impl(c, D.pointer, args.as_array());
        found = true;
      }
  
      });
  
    if (!found)
    {
      throw std::invalid_argument(&quot;Invalid method name&quot;);
    }
  
    return result;
  }
  
  struct Object
  {
    std::string greet(std::string const&amp; who)
    {
      return &quot;Hello, &quot; + who + &quot;!&quot;;
    }
  
    int add(int x, int y)
    {
      return x + y;
    }
    int foobar()
    {
      std::cout &lt;&lt; &quot;I'm stupid!&quot; &lt;&lt; std::endl;
      return 1;
    }
  };
  
  BOOST_DESCRIBE_STRUCT(Object, (), (greet, add, foobar))
  
  int main()
  {
    Object obj;
    std::cout &lt;&lt; call(obj, &quot;greet&quot;, { &quot;world&quot; }) &lt;&lt; std::endl;
    std::cout &lt;&lt; call(obj, &quot;add&quot;, { 1, 2 }) &lt;&lt; std::endl;
    boost::json::value sc{};
    std::cout &lt;&lt; call(obj, &quot;add&quot;, sc) &lt;&lt; std::endl;
  }
  </code></pre>
  <p>The part I added is</p>
  <pre class="lang-cpp prettyprint-override"><code>int foobar()
  {
      std::cout &lt;&lt; &quot;I'm stupid!&quot; &lt;&lt; std::endl;
      return 1;
  }
  </code></pre>
  <p>and</p>
  <pre class="lang-cpp prettyprint-override"><code>boost::json::value sc{};
  std::cout &lt;&lt; call(obj, &quot;foobar&quot;, sc) &lt;&lt; std::endl;
  </code></pre>
  <p>output:</p>
  <pre class="lang-bash prettyprint-override"><code>error C2672: 'call_impl': no matching overloaded function found
  </code></pre>
  <p>I know I can add an overload of call_impl and modify call to:</p>
  <pre class="lang-cpp prettyprint-override"><code>  boost::mp11::mp_for_each&lt;Fd&gt;([&amp;](auto D) {
      if (!found &amp;&amp; method == D.name)
      {
        auto temp = args.as_array();
        std::cout &lt;&lt; typeid(temp).name() &lt;&lt; std::endl;
        if (!temp.empty())
        result = call_impl(c, D.pointer,temp );
        else
          result = call_impl(c, D.pointer);
        found = true;
      }});
  </code></pre>
  <p>my question here is:</p>
  <ol>
  <li>how to construct a boost::json::value that contains empty values，so I can use it to call that function.</li>
  </ol>
  <p>I think I've described my problem clearly, so many of my attempts and manipulations are so wrong that they don't need to be written, but it still warns me &quot;It looks like your post is mostly code; please add some more details.&quot; ...</p>
  <p>OS:windows11<br />
  IDE:visual studio2019</p>