Search Results

Search found 1026 results on 42 pages for 'func'.

Page 32/42 | < Previous Page | 28 29 30 31 32 33 34 35 36 37 38 39  | Next Page >

  • Adapting non-iterable containers to be iterated via custom templatized iterator

    - by DAldridge
    I have some classes, which for various reasons out of scope of this discussion, I cannot modify (irrelevant implementation details omitted): class Foo { /* ... irrelevant public interface ... */ }; class Bar { public: Foo& get_foo(size_t index) { /* whatever */ } size_t size_foo() { /* whatever */ } }; (There are many similar 'Foo' and 'Bar' classes I'm dealing with, and it's all generated code from elsewhere and stuff I don't want to subclass, etc.) [Edit: clarification - although there are many similar 'Foo' and 'Bar' classes, it is guaranteed that each "outer" class will have the getter and size methods. Only the getter method name and return type will differ for each "outer", based on whatever it's "inner" contained type is. So, if I have Baz which contains Quux instances, there will be Quux& Baz::get_quux(size_t index), and size_t Baz::size_quux().] Given the design of the Bar class, you cannot easily use it in STL algorithms (e.g. for_each, find_if, etc.), and must do imperative loops rather than taking a functional approach (reasons why I prefer the latter is also out of scope for this discussion): Bar b; size_t numFoo = b.size_foo(); for (int fooIdx = 0; fooIdx < numFoo; ++fooIdx) { Foo& f = b.get_foo(fooIdx); /* ... do stuff with 'f' ... */ } So... I've never created a custom iterator, and after reading various questions/answers on S.O. about iterator_traits and the like, I came up with this (currently half-baked) "solution": First, the custom iterator mechanism (NOTE: all uses of 'function' and 'bind' are from std::tr1 in MSVC9): // Iterator mechanism... template <typename TOuter, typename TInner> class ContainerIterator : public std::iterator<std::input_iterator_tag, TInner> { public: typedef function<TInner& (size_t)> func_type; ContainerIterator(const ContainerIterator& other) : mFunc(other.mFunc), mIndex(other.mIndex) {} ContainerIterator& operator++() { ++mIndex; return *this; } bool operator==(const ContainerIterator& other) { return ((mFunc.target<TOuter>() == other.mFunc.target<TOuter>()) && (mIndex == other.mIndex)); } bool operator!=(const ContainerIterator& other) { return !(*this == other); } TInner& operator*() { return mFunc(mIndex); } private: template<typename TOuter, typename TInner> friend class ContainerProxy; ContainerIterator(func_type func, size_t index = 0) : mFunc(func), mIndex(index) {} function<TInner& (size_t)> mFunc; size_t mIndex; }; Next, the mechanism by which I get valid iterators representing begin and end of the inner container: // Proxy(?) to the outer class instance, providing a way to get begin() and end() // iterators to the inner contained instances... template <typename TOuter, typename TInner> class ContainerProxy { public: typedef function<TInner& (size_t)> access_func_type; typedef function<size_t ()> size_func_type; typedef ContainerIterator<TOuter, TInner> iter_type; ContainerProxy(access_func_type accessFunc, size_func_type sizeFunc) : mAccessFunc(accessFunc), mSizeFunc(sizeFunc) {} iter_type begin() const { size_t numItems = mSizeFunc(); if (0 == numItems) return end(); else return ContainerIterator<TOuter, TInner>(mAccessFunc, 0); } iter_type end() const { size_t numItems = mSizeFunc(); return ContainerIterator<TOuter, TInner>(mAccessFunc, numItems); } private: access_func_type mAccessFunc; size_func_type mSizeFunc; }; I can use these classes in the following manner: // Sample function object for taking action on an LMX inner class instance yielded // by iteration... template <typename TInner> class SomeTInnerFunctor { public: void operator()(const TInner& inner) { /* ... whatever ... */ } }; // Example of iterating over an outer class instance's inner container... Bar b; /* assume populated which contained items ... */ ContainerProxy<Bar, Foo> bProxy( bind(&Bar::get_foo, b, _1), bind(&Bar::size_foo, b)); for_each(bProxy.begin(), bProxy.end(), SomeTInnerFunctor<Foo>()); Empirically, this solution functions correctly (minus any copy/paste or typos I may have introduced when editing the above for brevity). So, finally, the actual question: I don't like requiring the use of bind() and _1 placeholders, etcetera by the caller. All they really care about is: outer type, inner type, outer type's method to fetch inner instances, outer type's method to fetch count inner instances. Is there any way to "hide" the bind in the body of the template classes somehow? I've been unable to find a way to separately supply template parameters for the types and inner methods separately... Thanks! David

    Read the article

  • how to call a php class function directly using ajax?

    - by payling
    Is it possible to call a php class function DIRECTLY using ajax? Something like below... except ajax... myclass::myfunction(); I've been using the jquery library to work with AJAX. $.get('control.php', {func: funcName, arg1: arg1}); The above is similar to what I'm trying to achieve MINUS the control.php; I'm not sure if this is even possible, but I just thought it would be nice to skip the landing page (control.php) that recieves the funcName. I have a bunch of conditional statements that sort out what class function to run based on the funcName recieved. It seems kind of silly to do this, to have a separate page just to handle function calls. Is there a better way?

    Read the article

  • Millionth number in the serie 2 3 4 6 9 13 19 28 42 63 ... ?

    - by HH
    It takes about minute to achieve 3000 in my comp but I need to know the millionth number in the serie. The definition is recursive so I cannot see any shortcuts except to calculate everything before the millionth number. How can you fast calculate millionth number in the serie? Serie Def n_{i+1} = \floor{ 3/2 * n_{i} } and n_{0}=2. Interestingly, only one site list the serie according to Goolge: this one. Too slow Bash code #!/bin/bash function serie { n=$( echo "3/2*$n" | bc -l | tr '\n' ' ' | sed -e 's@\\@@g' -e 's@ @@g' ); # bc gives \ at very large numbers, sed-tr for it n=$( echo $n/1 | bc ) #DUMMY FLOOR func } n=2 nth=1 while [ true ]; #$nth -lt 500 ]; do serie $n # n gets new value in the function throught global value echo $nth $n nth=$( echo $nth + 1 | bc ) #n++ done

    Read the article

  • How to compile using gcc but without using _alloca ?

    - by shkim
    For some reason, I should use gcc to compile a C file, then link against Visual C++ 2008 project. (I used the current latest gcc version: cygwin gcc 4.3.4 20090804.) But there is one problem: gcc always allocate a big array with _alloca, and VC linker can't resolve the symbol __alloca. for example, int func() { int big[10240]; .... } this code makes the _alloca dependency although I didn't call the _alloca function explicitly. (array size matters. if i change 10240 - 128, everything ok) I tried gcc option -fno-builtin-alloca or -fno-builtin, but no luck. Is it possible to make gcc not to use _alloca ? (or adjust the threshold?)

    Read the article

  • Mock Objects properties not changing

    - by frictionlesspulley
    I am new to using Mock test in .Net. I am testing out a financial transaction which is of the following nature: int amt =20; //sets all the props and func and returns a FinaceAccount. //Note I did not SetUp the amt of the account. var account =GetFinanceAccount() //service layer to be tested _financeService.tranx(account,amt); //checks if the amt was added to the account.amt //here the amt comes out same as that set in GetFinanceAccount. Assert.AreEqual(account.amt ,amt) I know that the function tranx works correctly but there is an issue with the test. Are there any GOOD reference material on Mocking in .Net

    Read the article

  • get value of a property o => o.Property1 , defined in lambda

    - by Omu
    I need to get the value of a property defined in a lambda public static MvcHtmlString MyHelper<T, TProperty>( this HtmlHelper<T> html, Expression<Func<T, TProperty>> prop) { var value = \\ get the value of Prop1 (not the name "Prop1") ... } the intended usage is something like: public class FooViewModel { public string Prop1 { get;set; } } <%@ Page ViewPage<FooViewModel> %> <%=Html.MyHelper(o => o.Prop1) %>

    Read the article

  • auto_inline - inadequate documentation

    - by Mick
    I want to disable inlining for a particular function. What the compiler does for everything else should be as specified in the project properties. I found a page on a forum which suggested the following: #pragma auto_inline(off) void func() { } #pragma auto_inline() The author suggested that calling auto_inline() with no arguments will set the compiler to revert to doing whatever the default action was before the call to auto_inline(off). Can anyone confirm that this works for visual studio 2008? I ask because the VS2008 documentation makes no mention at all of what happens if you call this function with no arguments.

    Read the article

  • Prototype Element.remove() not working in IE

    - by Gonçalo Queirós
    Hi there. I have a javascript function that gets a DIV by an ID and makes a clone. Then, removes the original DIV from DOM and inserts the cloned object..Everything works fine, except in IE, because the original DIV is never removed... var loadingDiv = $(Sybil.conf.loadingDivId), loadingClone = loadingDiv.clone(true); console.log($$('.loadingImg')); loadingDiv.remove(); //Insert the loading div on the page again elt.insert({after: loadingClone}); [loadingClone].invoke(func); console.log($$('.loadingImg')); The div also has a span inside with the class "loadingImg", so i just used the console.log to check how many elements there are. FF always prints [span.loadingImg] but IE prints [span.loadingImg,span.loadingImg] on the second console.log... Any idea of what might be happening? Thanks

    Read the article

  • XCode 5 says I got a duplicate, which I don't

    - by GoodMove
    The point is every time I try to run a C++ code in XCode 5 (the file s "File.cpp") xcode returns this: duplicate symbol _main ld: 1 duplicate symbol for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation) And it only returns the error, when I got the following function whatever it contains: int main() { } I checked the folder, which XCode points to (where it says the duplicates are placed), but didn't find anything though. What am I supposed to do??? #include "File.h" using namespace std; void func (void){ cout << "Hello World!" << endl; }

    Read the article

  • How do I get a Type[] with arguments from a MethodCallExpression?

    - by Tomas Lycken
    I'm reflecting over a class (in a unit test of said class) to make sure its members have all the required attributes. To do so, I've constructed a couple of helpers, that take an Expression as an argument. I do some checks for it, and take slightly different actions depending on what type of Expression it is, but it's basically the same. Now, my problem is that I have several methods with the same name (but different signatures), and the following code throws an AmbiguousMatchException: // TOnType is a type argument for the type where the method is declared // mce is the MethodCallExpression var m = typeof(TOnType).GetMethod(mce.Method.Name); Now, if I could add an array of Type[] with the types of the arguments to this method as a second parameter to .GetMethod(), the problem would be solved. But how do I find this Type[] array that I need? I have cast the Expression<Func<...>> to an Expression, and then to a MethodCallExpression, and in this method the contents of <...> is not known.

    Read the article

  • subscribing an event to a class object before initializing it.

    - by GN
    I have two classes class A and B.I have a delegate n event published in class B.The class B object is declared in class A.All he functionality dependes on the parameterised constru ctor of class B. Before initializing the object of class B i need to subscibe the event for it.how to do it? e.g public class B { public delegate void myDel(string); public event myDel myEvent; B(object obj) { ----------------- ------------------ } } class A { A objA; class XYZ objXYZ; void func() { objA.myEvent+=new myDel(); objA=new A(objXYZ); // hw to attain this? } }

    Read the article

  • Create an Action<T> to "set" a property, when I am provided with the LINQ Expression for the "get"

    - by Alex
    I'd like to be able to generate a compiled expression to set a property, given the lambda expression that provides the "get" method for a property. Here's what I'm looking for: public Action<int> CreateSetter<T>(Expression<Func<T, int>> getter) { // returns a compiled action using the details of the getter expression tree, or null // if the write property is not defined. } I'm still trying to understand the various types of Expression classes, so if you can point me in the right direction that would be great.

    Read the article

  • How to rewrite the following?(C#3.0)

    - by Newbie
    I am trying to write the following double sum_res = 0.0; double yhat = 0; double res = 0; int n = 0; for(int i=0;i<x.Count;i++) { yhat = inter + (slp*x[i]); res = yhat - y[i]; n++; } using lambda but somehow not able to get it work(compile time error) Enumerable.Range(0, x.Count).Select(i => { yhat = inter + (slp * x[i]); res = yhat - y[i]; sum_res += res * res; n++; }); Error: The type arguments for method 'System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable, System.Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly. Help needed. Thanks

    Read the article

  • Emacs auto-minor-mode based on extension

    - by vermiculus
    I found this question somewhat on the topic, but is there a way [in emacs] to set a minor mode (or a list thereof) based on extension? For example, it's pretty easy to find out that major modes can be manipulated like so (setq auto-mode-alist (cons '("\\.notes$" . text-mode) auto-mode-alist)) and what I'd ideally like to be able to do is (setq auto-minor-mode-alist (cons '("\\.notes$" . auto-fill-mode) auto-minor-mode-alist)) The accept answer of the linked question mentions hooks, specifically temp-buffer-setup-hook. To use this, you have to add a function to the hook like so (add-hook 'temp-buffer-setup-hook 'my-func-to-set-minor-mode) My question is two-fold: Is there an easier way to do this, similar to major modes? If not, how would one write the function for the hook? It needs to check the file path against a regular expression. If it matches, activate the desired mode (e.g. auto-fill-mode).

    Read the article

  • How is a set partitioned into valid and invalid items using LINQ?

    - by Aaron Anodide
    Is there a way to write a single LINQ expression to get the same result of the following code? var validations = new Func<conversion, bool>[] { c => c.affiliate.affiliate_id > 0, c => c.campaign_id > 0 }; var invalidConversions = from c in extractedConversions where validations.Any(valid => !valid(c)) select c; var validConversions = from c in extractedConversions where validations.All(valid => valid(c)) select c;

    Read the article

  • Call function by pointer and set parametrs in memory block

    - by Ellesmess Glain
    Hi, I've little problem : I'm solving problem with calling function by pointer and passing to it parameters in continuous memory block. My goal is to have function named e.g CallFunc(void * func,void *params, unsigned int param_length); that I'll send function pointer, pointer to function's parameters and eventually parameters length and this calling function will call passed function with it's parameters. I will like write this in C/C++, but if somebody has idea, how this resolve in other language, that supports DLL generation and exportet functions, it will be fine too. Thanks for answers, Ellesmess P.S. I'm sorry about my English, but I'm Czech, thanks :o)

    Read the article

  • C++ template restrictions

    - by pingvinus
    I wondering is there any way to set restrictions on template class? Specify that every type substituted in template must have specific ancestor (realize some interface). template < class B > //and every B must be a child of abstract C class A { public: B * obj; int f() { return B::x + this->obj->f(); } }; Like = in haskell func :: (Ord a, Show b) => a -> b -> c

    Read the article

  • How to pass an anonymous array of strings to a JavaScript function?

    - by abatishchev
    I want to pass to an array of controls' IDs to a javascript script function so it will switch control's enable state. For example, in C# it would be like this: func(false, new[] { "Control1", "Control2", "Control3" }); In that function I want to find corresponding controls and disable/enable them. For one control I do this next way: <script type="text/javascript" language="javascript"> function switchControls(value, arr) { for (var n = 0; n < array.length; n++) document.getElementById(n).disabled = value; } </script> <asp:CheckBox runat="server" onclick="switchControls(this.checked, [ '<%= Control1.ClientID %>', '<%= Control2.ClientID %>' ])" Text="Take?" /> How to implement this properly? Have I to use jQuery?

    Read the article

  • Problem in populating a dictionary object using Enumerable.Range() (C#3.0)

    - by Newbie
    If I do for (int i = 0; i < appSettings.Count; i++) { string key = appSettings.Keys[i]; euFileDictionary.Add(key, appSettings[i]); } It is working fine. When I am trying the same thing using Enumerable.Range(0, appSettings.Count).Select(i => { string Key = appSettings.Keys[i]; string Value = appSettings[i]; euFileDictionary.Add(Key, Value); }).ToDictionary<string,string>(); I am getting a compile time error The type arguments for method 'System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable, System.Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly. Any idea? Using C#3.0 Thanks

    Read the article

  • Error when customize ValidationMessageFor

    - by user1542080
    i want to customize ValidationMessageFor which display error. when i run application, a get an error : No overload for method 'ValidationMessageFor' takes 1 arguments I'm understand my error, but i don't know how to fix it ? I need some suggest . Thanks you for reading! My code : using System.Linq.Expressions; using System.Web; using System.Web.Mvc; namespace OurCompanyUI.app_code { public static class MyHtml { public static MvcHtmlString ValidationMessageFor<TModel, TProperty>( this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, string validationMessage, IDictionary<string, Object> htmlAttributes ) { string modelName = ExpressionHelper.GetExpressionText(expression); TagBuilder p = new TagBuilder("p"); p.InnerHtml = htmlHelper.ValidationMessageFor(htmlHelper,expression).ToString(); // p.InnerHtml = htmlHelper.ValidationMessageFor().ToString(); return MvcHtmlString.Create(p.ToString(TagRenderMode.Normal)); } } }

    Read the article

  • Why use C typedefs rather than #defines?

    - by me_and
    What advantage (if any) is there to using typedef in place of #define in C code? As an example, is there any advantage to using typedef unsigned char UBYTE over #define UBYTE unsigned char when both can be used as void func() { UBYTE byte_value = 0; /* Do some stuff */ return byte_value; } Obviously the pre-processor will try to expand a #define wherever it sees one, which wouldn't happen with a typedef, but that doesn't seem to me to be any particular advantage or disadvantage; I can't think of a situation where either use wouldn't result in a build error if there was a problem.

    Read the article

  • Different methods using Functors/Delegates in c#

    - by mo alaz
    I have a method that I call multiple times, but each time a different method with a different signature is called from inside. public void MethodOne() { //some stuff *MethodCall(); //some stuff } So MethodOne is called multiple times, each time with a different *MethodCall(). What I'm trying to do is something like this : public void MethodOne(Func<> MethodCall) { //some stuff *MethodCall; //some stuff } but the Methods that are called each have a different return type and different parameters. Is there a way to do this using Functors? If not, how would I go about doing this? Thank you!

    Read the article

  • What is wrong with the below statement(C#3.0 / Lambda)

    - by Newbie
    what is wrong in the below Enumerable.Range(0, objEntityCode.Count - 1).Select(i => { options.Attributes[i] = new EntityCodeKey { EntityCode = objEntityCode[i].EntityCodes , OrganizationCode = Constants.ORGANIZATION_CODE }; }) .ToArray(); Throwing error The type arguments for method 'System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable, System.Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly. But this works Enumerable.Range(0, objEntityCode.Count - 1).ToList().ForEach(i => { options.Attributes[i] = new EntityCodeKey { EntityCode = objEntityCode[i].EntityCodes , OrganizationCode = Constants.ORGANIZATION_CODE }; } ); Using C#3.0. Purpose: I am learning LINQ / LAMBDA and trying to do the same program in different way. Thanks.

    Read the article

  • realizing number ...how?? [closed]

    - by gcc
    i hold input like that A is char pointer A[0]=n A[1]=j A[2]=n A[3]=d . there is one number in A[] and every A[i] is important for me because what will i do in next step is determined by input in A[i] or A[n] A[j]=$ . A[i]=14(any number) . . int func(int temp) { if(temp=='n') ..do something then return 10; if(temp=='j') .. return 11; if(temp=='d') .. return 12; if(........) when temp find/realize number ,i wanna return 13; in if statement, what code should i write } how i can do }

    Read the article

< Previous Page | 28 29 30 31 32 33 34 35 36 37 38 39  | Next Page >