Moderators: phlip, Moderators General, Prelates
vector<map<string, SomeHugeComplexType>> vec;
/*...*/
transform(begin(vec), end(vec), [](auto& x){ /* do stuff */ }); // alas this will not compilevector<map<string, SomeHugeComplexType>> vec;
/*...*/
transform(begin(vec), end(vec), [](decltype(*begin(vec))& x){ /* do stuff */ }); // alas this will compile
Sc4Freak wrote:What I would like before a variadic lambda is just a simple polymorphic lambda - that is, a template lambda with an automatically deduced type.
- Code: Select all
vector<map<string, SomeHugeComplexType>> vec;
/*...*/
transform(begin(vec), end(vec), [](auto& x){ /* do stuff */ }); // alas this will not compile
The compiler already knows what the type of x is.
foo( [](auto& x) { ... }) // use
template<typename Functor>
void foo(Functor f) {
f(1);
f(1.0);
}struct desugared_lambda {
template<typename Param>
Whatever operator() (Param & x) { ... }
};struct MyLambda1
{
void operator()(map<string, SomeHugeComplexType>>& x)
{
/* ... */
}
}struct MyLambda2
{
template <typename T>
void operator()(T& x)
{
/* ... */
}
}foo([](auto& x) { x = x * 3 / 2; })
template<typename Functor>
void foo(Functor f) {
int a = 1;
double b = 1.0;
f(a);
f(b);
// a is now 1
// b is now 1.5
}foo([](template & x) { x = x * 3 / 2; })void Frobnicate(auto& x) {++x;}Jplus wrote:That would pretty much amount to introducing Haskell-style type deduction into C++.
void foo(template x, template y) { ... }template<typename Tx, typename Ty>
void foo (Tx x, Ty y) {...}Sc4Freak wrote:Yes, the way this would be implemented would be to create a templated operator(). Normally a lambda can be expressed as a simple functor:
- Code: Select all
struct MyLambda1
{
void operator()(map<string, SomeHugeComplexType>>& x)
{
/* ... */
}
}
In a polymorphic lambda, the type(s) are merely replaced my template parameters:
- Code: Select all
struct MyLambda2
{
template <typename T>
void operator()(T& x)
{
/* ... */
}
}
And normal template instantiation rules apply. In your example, two instances of the lambda would be instantiated. For example:
- Code: Select all
foo([](auto& x) { x = x * 3 / 2; })
template<typename Functor>
void foo(Functor f) {
int a = 1;
double b = 1.0;
f(a);
f(b);
// a is now 1
// b is now 1.5
}
On the surface it seems to be a perfectly logical and consistent feature that would have made lambdas much easier to use. Why the C++ standards committee decided to omit it is beyond me.
template<typename T>
function<T(T)> createLambda() { return [](T t) { return 2*t; }; }
auto lambda = [](template x){return x+1;}
std::function<what?> func = lambda;auto lambda = [](template x){return x+1;}
std::function<int(int)> func = lambda;auto lambda = [](template x){return x+1;}
std::function<int(int)> func = lambda<int>;auto lambda = template<typename T> [](T x){return x+1;}
std::function<int(int)> func = lambda<int>;
Yakk wrote:And there is the std::function problem. Ie:
- Code: Select all
auto lambda = [](template x){return x+1;}
std::function<what?> func = lambda;
type enumeration {int, double, long, mystruct} E;
std::function< for e in E e(e) > foo = template<T>[]( T x ) { return ++x; };
You, sir, name? wrote:If you have over 26 levels of nesting, you've got bigger problems ... than variable naming.
suffer-cait wrote:it might also be interesting to note here that i don't like 5 fingers. they feel too bulky.
Yakk wrote:This is someone doing pretty much what you are asking to do:
http://www.howto-outlook.com/howto/senddocasmail.htm
This is not mac-centric. I don't think there is much need for it to be a mac based solution.
sdkelso wrote:Yakk wrote:This is someone doing pretty much what you are asking to do:
http://www.howto-outlook.com/howto/senddocasmail.htm
This is not mac-centric. I don't think there is much need for it to be a mac based solution.
I'm confused. That looks good, but I can't use it on Mac OSX, can I? I don't even have Outlook, and since the code is written for a Windows OS wouldn't it be looking in the wrong places on a Mac?
Eh, I think the problem is above me. Thanks for the help guys.
Xeio wrote:I kinda wish $programming_language did not have null values
Steax wrote:I actually have a near-complete solution for what you needed in my last post.
Hrmmmm, no. Nulls can be useful (though some markup for enforcing not-null parameters functions would be nice).b.i.o wrote:FTFYXeio wrote:I kinda wish $programming_language did not have null values
Collection<IOrder> Orders = Dal.GetOrders(o => o.OrderDate > DateTime.Now.AddDays(-1));
//Compiler error, because GetOrders returns an object of type Collection<Order>, even though Order implements IOrder
//Works in 4.5, like magic and stuff
Collection<Derived> cd = new Collection<Derived>();
Collection<Base> cb = cd; // use covariance
cb.add(new Base()); // locally correct (cb has a .add(Base) method) but globally wrong (cd should not contain any Base objects)IEnumerable<IOrder> Orders = Dal.GetOrders(o => o.OrderDate > DateTime.Now.AddDays(-1));Xeio wrote:Hrmmmm, no. Nulls can be useful (though some markup for enforcing not-null parameters functions would be nice).b.i.o wrote:FTFYXeio wrote:I kinda wish $programming_language did not have null values
Without null I'd have to either throw exceptions or otherwise keep track of a success/failure for many functions. Granted, there are probably other language constructs (not specifically in C#) that could handle that, but they're all as messy as null from what I'm aware.
True, it is perfectly valid, though convention usually dictates not storing null values, similarly to how conventions dictates to never return a null if the type you're returning is a collection.*You, sir, name? wrote:Doesn't make a lot of sense. Java collections deal with references. null is a perfectly valid reference -- there is no real reason why it wouldn't be allowed. It's not like a C++ collection, which actually creates a new copy of the object and stores that.
Users browsing this forum: No registered users and 4 guests