Loading ...
Sorry, an error occurred while loading the content.

[boost] Re: Maybe generic meta-programming

Expand Messages
  • Dave Abrahams
    ... I m not convinced: 1. compile-time assertions will be primarily for the advanced user and library programmer. The library s clients will get the benefit of
    Message 1 of 7 , Dec 1, 1999
    • 0 Attachment
      Beman wrote:
      > One problem we ran into was that we wanted something which was not
      > subject to inadvertent misuse. For example, we had several
      > implementations of a "require" template class, which you could
      > inherit or instantiate:
      >
      > template<typename T>
      > class foo : require< std::numeric_limits<T>::is_integer > {...};
      >
      > The problem was that it could be misused:
      >
      > template<typename T>
      > class foo
      > {
      > require< std::numeric_limits<T>::is_integer >;
      > };
      >
      > This code looks right, but is actually totally ineffective (because
      > it should have been coded "require<
      > std::numeric_limits<T>::is_integer > some_name;").
      >
      > Any compile time assert should be bullet-proof, IMO.

      I'm not convinced:
      1. compile-time assertions will be primarily for the advanced user and
      library programmer. The library's clients will get the benefit of the assert
      at compile time, when used properly

      2. The problem you describe is no worse than many other pitfalls in the
      language; you have to know the language rules.

      e.g.

      class mutex;
      void foo()
      {
      mutex(); // Oops; does nothing!

      ...
      }

      3. You could improve things by changing the name to require_t, making the
      error you describe less likely.

      -D
    • Bill Wade
      ... A trick to consider (I ve never actually used this) is to require a mutex& as an unused argument in all constructors. So mutex(); // Compiler error
      Message 2 of 7 , Dec 1, 1999
      • 0 Attachment
        > Dave wrote

        > 2. The problem you describe is no worse than many other pitfalls in the
        > language; you have to know the language rules.
        >
        > e.g.
        >
        > class mutex;
        > void foo()
        > {
        > mutex(); // Oops; does nothing!
        > }

        A trick to consider (I've never actually used this) is to require a mutex&
        as an unused argument in all constructors. So

        mutex(); // Compiler error
        mutex m = m; // Ok

        or

        foo(args); // Compiler error
        foo f = foo(args, f); // Ok

        The only way to create a temporary is with the help of some non-temporary
        that happens to be available. It doesn't seem like a likely mistake for
        classes like require and mutex.
      • Valentin Bonnard
        ... Hum... I don t see how it can be parsed... -- Valentin Bonnard
        Message 3 of 7 , Dec 2, 1999
        • 0 Attachment
          Beman Dawes wrote:

          > The problem was that it could be misused:
          >
          > template<typename T>
          > class foo
          > {
          > require< std::numeric_limits<T>::is_integer >;
          > };
          >
          > This code looks right, but is actually totally ineffective

          Hum... I don't see how it can be parsed...

          --

          Valentin Bonnard
        Your message has been successfully submitted and would be delivered to recipients shortly.