Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > de.comp.lang.iso-c++ > #1957

Re: typedef auf variadic template

From Stefan Reuther <stefan.news@arcor.de>
Newsgroups de.comp.lang.iso-c++
Subject Re: typedef auf variadic template
Date 2016-11-20 11:14 +0100
Organization A noiseless patient Spider
Message-ID <o0s0im.1v4.1@stefan.msgid.phost.de> (permalink)
References <o0n81u$jmv$1@news.albasani.net>

Show all headers | View raw


Am 18.11.2016 um 16:51 schrieb Markus Donath:
> template<typename T, T ... items>
> inline bool is_in(const T& item) {
>   T match_items[sizeof...(items)] = { items... };
>   for(int i = 0; i < sizeof...(items); ++i)
>     if(item == match_items[i])
>       return true;
>   return false;
> }

Wie wär's damit:
    template<typename T>
    inline bool is_in(const T& item, const T& value)
    {
        return item == value;
    }

    template<typename T, typename... Values>
    inline bool is_in(const T& item, const T& value, Values... values)
    {
        return item == value || is_in(item, values...);
    }

Aufruf als 'is_in(n, 3, 5, 27, -1327)'. Nachteil: da der Typ nicht
angegeben ist, müssen die Parametertypen halt von vornherein passen.


  Stefan

Back to de.comp.lang.iso-c++ | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

typedef auf variadic template Markus Donath <nntp@online.de> - 2016-11-18 16:51 +0100
  Re: typedef auf variadic template Stefan Reuther <stefan.news@arcor.de> - 2016-11-20 11:14 +0100
    Re: typedef auf variadic template Markus Donath <nntp@online.de> - 2016-11-21 08:58 +0100
    Re: typedef auf variadic template Markus Donath <nntp@online.de> - 2016-11-21 11:45 +0100
    Re: typedef auf variadic template Thomas Dorner <td-dclic01@th-dorner.de> - 2016-11-21 15:42 +0100
      Re: typedef auf variadic template Markus Donath <nntp@online.de> - 2016-11-22 10:07 +0100
  Re: typedef auf variadic template nntp@mailinator.com - 2016-12-20 09:54 +0000
    Re: typedef auf variadic template Markus Donath <nntp@online.de> - 2016-12-22 14:30 +0100
  Re: typedef auf variadic template ram@zedat.fu-berlin.de (Stefan Ram) - 2016-12-20 13:58 +0000
    Re: typedef auf variadic template Markus Donath <nntp@online.de> - 2016-12-22 14:34 +0100
    Re: typedef auf variadic template Markus Donath <nntp@online.de> - 2016-12-22 14:39 +0100

csiph-web