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


Groups > comp.lang.c++ > #11052

Re: Limiting function input only to __int64 but not int...

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c++
Subject Re: Limiting function input only to __int64 but not int...
Date 2011-10-24 11:49 +1300
Message-ID <9gjjvjFk5cU5@mid.individual.net> (permalink)
References <j824fk$5bf$1@gregory.bnet.hr>

Show all headers | View raw


On 10/24/11 11:28 AM, A wrote:
> Is there a way (except overloading) to limit function input to accept
> __int64 but to get a compiler (preferable) or runtime (less preferable)
> error if it is called with int?
>
> for example:
>
> void myfunction(__int64 param)    // Accepts only __int64 as input and no
> smaller
> {
> }
>
> myfunction((__int64)1);    // Call OK
> myfunction((int)1);        // Call fails or better - compiler reports error

You can use a function template to force a link error:

#include <stdint.h>

template <typename T> void f( T n );

template <> void f( int64_t n ) // Specialise for acceptable types
{
}

Or give the function template a body to force a compiler warning:

template <typename T> void f( T n )
{
   T tmp = n/0;
}

-- 
Ian Collins

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Limiting function input only to __int64 but not int... "A" <a@a.a> - 2011-10-24 00:28 +0200
  Re: Limiting function input only to __int64 but not int... Ian Collins <ian-news@hotmail.com> - 2011-10-24 11:49 +1300
    Re: Limiting function input only to __int64 but not int... Juha Nieminen <nospam@thanks.invalid> - 2011-10-24 08:08 +0000
      Re: Limiting function input only to __int64 but not int... yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2011-10-24 14:24 +0000
  Re: Limiting function input only to __int64 but not int... Marc <marc.glisse@gmail.com> - 2011-10-23 22:52 +0000
    Re: Limiting function input only to __int64 but not int... "A" <a@a.a> - 2011-10-24 01:32 +0200
  Re: Limiting function input only to __int64 but not int... Goran <goran.pusic@gmail.com> - 2011-10-23 23:29 -0700
    Re: Limiting function input only to __int64 but not int... "A" <a@a.a> - 2011-10-24 17:11 +0200
      Re: Limiting function input only to __int64 but not int... Robert Wessel <robertwessel2@yahoo.com> - 2011-10-24 12:17 -0500
        Re: Limiting function input only to __int64 but not int... Richard Damon <news.x.richarddamon@xoxy.net> - 2011-10-24 13:49 -0400
        Re: Limiting function input only to __int64 but not int... "A" <a@a.a> - 2011-10-25 00:12 +0200
          Re: Limiting function input only to __int64 but not int... Richard Damon <news.x.richarddamon@xoxy.net> - 2011-10-24 20:20 -0400
          Re: Limiting function input only to __int64 but not int... Christian Gollwitzer <auriocus@gmx.de> - 2011-10-25 07:27 +0200
            Re: Limiting function input only to __int64 but not int... Arne Mertz <arnemertz@googlemail.com> - 2011-10-26 01:02 -0700
  Re: Limiting function input only to __int64 but not int... Marcel Müller <news.5.maazl@spamgourmet.com> - 2011-10-24 09:18 +0200
    Re: Limiting function input only to __int64 but not int... Ian Collins <ian-news@hotmail.com> - 2011-10-24 20:53 +1300
      Re: Limiting function input only to __int64 but not int... Ian Collins <ian-news@hotmail.com> - 2011-10-24 20:58 +1300

csiph-web