overloading

How to make a function to return really different types in fsharp?

邮差的信 提交于 2019-12-22 08:48:23
问题 Assume that there is a third-party library written in FSharp, it contains several generic classes, for example as follows: type FirstType<'a> has method DoWork , that accepts: first param of type FirstType<'a> , second param is a function of type ('a -> 'b) DoWork method return type is FirstType<'b> type SecondType<'a> has method DoWork , that accepts: first param of type SecondType<'a> , second param is a function of type ('a -> 'b) DoWork method return type is SecondType<'b> type ThirdType

Is there a reason that C99 doesn't support function overloading?

会有一股神秘感。 提交于 2019-12-22 05:37:18
问题 Apparently (at least according to gcc -std=c99 ) C99 doesn't support function overloading. The reason for not supporting some new feature in C is usually backward compatibility, but in this case I can't think of a single case in which function overloading would break backward compatibility. What is the reasoning behind not including this basic feature? 回答1: To understand why you aren't likely to see overloading in C, it might help to better learn how overloading is handled by C++. After

Overload resolution gets different result between gcc and clang

♀尐吖头ヾ 提交于 2019-12-22 05:23:10
问题 struct A { A(int);}; struct B { explicit B(A); B(const B&);}; B b({0}); gcc 5.1.0 gives the error /dev/fd/63:3:8: error: call of overloaded 'B(<brace-enclosed initializer list>)' is ambiguous /dev/fd/63:3:8: note: candidates are: /dev/fd/63:2:27: note: B::B(const B&) /dev/fd/63:2:21: note: B::B(A) while clang 3.6.0 succeeds. Which one is right? Why? For gcc 5.1.0: http://melpon.org/wandbox/permlink/pVe9eyXgu26NEX6X For clang 3.6.0: http://melpon.org/wandbox/permlink/WOi1md2dc519SPW0 This may

What does that have to do with function overloading?

只愿长相守 提交于 2019-12-22 05:04:08
问题 This is basically a copy from the example given in Item 21. Overriding Virtual Functions in Herb Sutter's book Exceptional C++ . #include <iostream> #include <complex> using namespace std; class Base { public: virtual void f(int); virtual void f(double); virtual ~Base() {}; }; void Base::f(int) { cout << "Base::f(int)" << endl; } void Base::f( double ) { cout << "Base::f(double)" << endl; } class Derived: public Base { public: void f(complex<double>); }; void Derived::f(complex<double>) {

Generics and calling overloaded method from difference class - precedence issue [duplicate]

浪尽此生 提交于 2019-12-22 04:06:09
问题 This question already has an answer here : Passing generic parameter results in wrong overload being called (1 answer) Closed 6 years ago . First of all, sorry for the title, but I couldn't think about anything better ... My problem can be presented by simple code sample: public static class Test<T> { public static int GetInt(T source) { return Convert.ToInt32(source); } } public static class Convert { public static int ToInt32(byte source) { return 30; } public static int ToInt32(object

Alternative for function overloading in Go?

只谈情不闲聊 提交于 2019-12-22 03:50:58
问题 Is it possible to work similar way like the function overloading or optional parameter in C# using Golang? Or maybe an alternative way? 回答1: 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

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

[亡魂溺海] 提交于 2019-12-22 01:52:10
问题 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() {

C11 type-generic expressions - why not just add function overloading?

。_饼干妹妹 提交于 2019-12-22 01:33:07
问题 I was just reading the Wikipedia article on C11, the new version of the C standard released in Dec 2011, and I saw that one of the added features was "type-generic expressions": Type-generic expressions using the _Generic keyword. For example, the following macro cbrt(x) translates to cbrtl(x) , cbrt(x) or cbrtf(x) depending on the type of x : #define cbrt(X) _Generic((X), long double: cbrtl, \ default: cbrt, \ float: cbrtf)(X) This looks pretty horrible to me - if they are going to change

chef rewind cookbook_file definition from a wrapper cookbook recipe

安稳与你 提交于 2019-12-22 01:32:26
问题 I am using an cookbook github.com opscode-cookbooks/openldap. I wrote an wrapper cookbook "lab_openldap" that includes "openldap::server" recipe. The server.rb recipe uses following clausule to upload the PEM file from cookbooks files/ssl/*.pem to server to the location node['openldap']['ssl_cert']. if node['openldap']['tls_enabled'] && node['openldap']['manage_ssl'] cookbook_file node['openldap']['ssl_cert'] do source "ssl/#{node['openldap']['server']}.pem" mode 00644 owner "root" group

overloaded __iter__ is bypassed when deriving from dict

◇◆丶佛笑我妖孽 提交于 2019-12-21 20:59:37
问题 Trying to create a custom case-insensitive dictionary, I came the following inconvenient and (from my point-of-view) unexpected behaviour. If deriving a class from dict , the overloaded __iter__ , keys , values functions are ignored when converting back to dict . I have condensed it to the following test case: import collections class Dict(dict): def __init__(self): super(Dict, self).__init__(x = 1) def __getitem__(self, key): return 2 def values(self): return 3 def __iter__(self): yield 'y'