Menu

Library design

Anonymous
2007-08-04
2013-04-18
  • Anonymous

    Anonymous - 2007-08-04

    What is the better usage ?
    There is a problem with templates in the current design.

    How it can be solved ?

    1.a.
    Some macros:
    template<typename T>
    void f(param int in a, param int out b)
    <i>// void f(::boost::call_traits< int >::param_type a, ::boost::call_traits< int >::reference b)</i>
    {
      std::cout << a;
      std::cin >> b;
    }

    int i = 0, j;
    f(i, j);

    1.b.
    Or maybe
    template<typename T>
    void f(param<int>in a, param<int>out b)
    <i>// void f(::boost::call_traits <int> ::param_type a, ::boost::call_traits <int> ::reference b)</i>
    {
      std::cout << a;
      std::cin >> b;
    }

    int i = 0, j;
    f(i, j);

    2.a.
    Some templates:
    template<typename T>
    void f(in_<T> a, out_<T> b)
    {
      std::cout << a;
      std::cin >> b;
    }

    int i = 0, j;
    f(in(i), out(j));

    2.b.
    Or maybe with some macro:
    Some templates:
    template<typename T>
    void f(in_<T> a, out_<T> b)
    {
      std::cout << a;
      std::cin >> b;
    }

    int i = 0, j;
    f(in i, out j);

     
    • Sergey Shandar

      Sergey Shandar - 2007-08-06

      It would be better if you rename the "out" parameter to "in_out" or "reference". C++ has only one "out", it is a function result. C# and COM have "out" parameters.

       
      • Anonymous

        Anonymous - 2007-08-07

        The only reason is for call semantics:

        E.g.:
        void f(out_<int> i);
        void g(inout_<int> i);

        int i;
        f(out(i));
        // f(inout(i)); // ERROR !
        g(inout(i));
        // g(out(i)); // ERROR !

         

Log in to post a comment.