overloading

Is there any guarantee on the order of substitution in a function template after type deduction?

老子叫甜甜 提交于 2019-12-05 01:06:20
Consider this function template: template<typename T> typename soft_error<T>::type foo(T, typename hard_error<T>::type) { } After deducing type T from the type of the first argument in the call to foo() , the compiler will proceed to substitute T and instantiate the function signature. If substitution for the return type gets executed first, causing a simple substitution failure, the compiler will discard this function template when computing the overload set and search for other viable overloads (SFINAE). On the other hand, if substitution for the second function parameter occurs first,

How can you overload a function in ActionScript?

元气小坏坏 提交于 2019-12-05 00:58:10
I want a function to be able to take in various types. AS3 doesn't support overloading directly... so I can't do the following: //THIS ISN'T SUPPORTED BY AS3 function someFunction(xx:int, yy:int, someBoolean:Boolean = true){ //blah blah blah } function someFunction(arr:Array, someBoolean:Boolean = true){ someFunction(arr[0], arr[1], someBoolean); } How can I work around it and still have a function that is able to take arguments of various types? zzzzBov If you just want to be able to accept any type, you can use * to allow any type: function someFunction( xx:*, yy:*, flag:Boolean = true ) {

Alternative for function overloading in Go?

别说谁变了你拦得住时间么 提交于 2019-12-05 00:39:56
Is it possible to work similar way like the function overloading or optional parameter in C# using Golang? Or maybe an alternative way? Neither function overloading nor optional arguments are directly supported. You could work around them building your own arguments struct. I mean like this (untested, may not work...) EDIT: now tested... package main import "fmt" func main() { args:=NewMyArgs("a","b") // filename is by default "c" args.SetFileName("k") ret := Compresser(args) fmt.Println(ret) } func Compresser(args *MyArgs) string { return args.dstFilePath + args.srcFilePath + args.fileName }

Why doesn't “use overload” work with “use namespace:autoclean”?

▼魔方 西西 提交于 2019-12-05 00:35:43
Ok just to sanity check overload doesnt seem to be working for me. I don't know if it's the version of perl I have, or the version of overload.pm, or something wrong with how I've implemented it, but this code doesnt work for me. perl version This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi overload version perl -Moverload -e 'print "$overload::VERSION\n";' 1.07 Token.pm package Token; use namespace::autoclean; use Data::Dumper; use Moose; use Moose::Util::TypeConstraints; use overload '+' => \&_overload_add, fallback => 1; has 'secretvalue' => ( is => 'rw', isa => 'Int'); sub

Function overloading — two functions only differ by a default parameter

旧街凉风 提交于 2019-12-05 00:16:53
问题 class A{ public: void foo(int x) { cout << "foo with one\n"; } void foo(int x, int y=10) { cout << "foo with two\n"; } }; int main() { A a; a.foo(1); //error? } So, why can't I overload void foo(int) with a function that takes a default parameter? 回答1: No you cannot overload functions on basis of value of the argument being passed, So overloading on the basis of value of default argument is not allowed either. You can only overload functions only on the basis of: Type of arguments Number of

Adding an attribute to a python dictionary from the standard library

☆樱花仙子☆ 提交于 2019-12-05 00:00:33
I was wondering if you could add an attibute to a python dictionary. class myclass(): def __init__(): self.mydict = {} #initialize a regular dict self.mydict.newattribute = "A description of what this dictionary will hold" >>>AttributeError: 'dict' object has no attribute 'newattribute' setattr(self.mydict,"attribute","A description of what this dictionary will hold" >>>AttributeError: 'dict' object has no attribute 'newattribute' Is there anyway to quickly add my description attribute without having to copy the dict class and overloading the constructor. I thought it would be simple, but I

php check if method overridden in child class

谁都会走 提交于 2019-12-04 23:38:15
Is it possible to check whether or not a method has been overridden by a child class in PHP? <!-- language: lang-php --> class foo { protected $url; protected $name; protected $id; var $baz; function __construct($name, $id, $url) { $this->name = $name; $this->id = $id; $this->url = $url; } function createTable($data) { // do default actions } } Child class: class bar extends foo { public $goo; public function createTable($data) { // different code here } } When iterating through an array of objects defined as members of this class, how can I check which of the objects has the new method as

Is it possible to legally overload a string literal and const char*?

女生的网名这么多〃 提交于 2019-12-04 23:34:05
Is it possible in C++11 to overload const char* 's and string literals ( const char[] )? The idea is to avoid having to call strlen to find the string length when this length is known already. This snippet breaks on G++ 4.8 and Clang++ 3.2: #include <stdio.h> #include <stdlib.h> #include <string.h> template<typename T, int N> void length(const T(&data)[N]) { printf("%u[]\n", N - 1); } template<typename T> void length(const T* data) { printf("*%u\n", (unsigned)strlen(data)); } int main() { length("hello"); const char* p = "hello"; length(p); return 0; } Error (Clang): test2.cpp:16:3: error:

How to find an overloaded method in Java?

荒凉一梦 提交于 2019-12-04 22:59:18
When writing something like doit(43, 44, "hello"); the compiler knows which overloaded method is to be called. When I want to do the same via reflection, I need to find out myself, that the method is doit(Integer, double, CharSequence...); and obtain it via something like Class[] types = {Integer.class, double.class, CharSequence[].class}; declaringClass.getDeclaredMethod("doit", types); I wonder if there's already something allowing me to write just Method m = getMethod(declaringClass, "doit", 43, 44, "hello"); I wonder if somebody did this already, as the JLS is a bit complicated in this

How does method overload resolution work (LINQ Where extension method)?

ⅰ亾dé卋堺 提交于 2019-12-04 22:56:56
问题 If I have a variable of type IQueryable<T> I have four extension methods for Where in namespace Systm.Linq available: public static IQueryable<T> Where<T>(this IQueryable<T> source, Expression<Func<T, bool>> predicate); public static IQueryable<T> Where<T>(this IQueryable<T> source, Expression<Func<T, int, bool>> predicate); public static IEnumerable<T> Where<T>(this IEnumerable<T> source, Func<T, bool> predicate); public static IEnumerable<T> Where<T>(this IEnumerable<T> source, Func<T, int,