Search Results

Search found 1157 results on 47 pages for 'recursive descent'.

Page 19/47 | < Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >

  • GCC ICE -- alternative function syntax, variadic templates and tuples

    - by Marc H.
    (Related to C++0x, How do I expand a tuple into variadic template function arguments?.) The following code (see below) is taken from this discussion. The objective is to apply a function to a tuple. I simplified the template parameters and modified the code to allow for a return value of generic type. While the original code compiles fine, when I try to compile the modified code with GCC 4.4.3, g++ -std=c++0x main.cc -o main GCC reports an internal compiler error (ICE) with the following message: main.cc: In function ‘int main()’: main.cc:53: internal compiler error: in tsubst_copy, at cp/pt.c:10077 Please submit a full bug report, with preprocessed source if appropriate. See <file:///usr/share/doc/gcc-4.4/README.Bugs> for instructions. Question: Is the code correct? or is the ICE triggered by illegal code? // file: main.cc #include <tuple> // Recursive case template<unsigned int N> struct Apply_aux { template<typename F, typename T, typename... X> static auto apply(F f, const T& t, X... x) -> decltype(Apply_aux<N-1>::apply(f, t, std::get<N-1>(t), x...)) { return Apply_aux<N-1>::apply(f, t, std::get<N-1>(t), x...); } }; // Terminal case template<> struct Apply_aux<0> { template<typename F, typename T, typename... X> static auto apply(F f, const T&, X... x) -> decltype(f(x...)) { return f(x...); } }; // Actual apply function template<typename F, typename T> auto apply(F f, const T& t) -> decltype(Apply_aux<std::tuple_size<T>::value>::apply(f, t)) { return Apply_aux<std::tuple_size<T>::value>::apply(f, t); } // Testing #include <string> #include <iostream> int f(int p1, double p2, std::string p3) { std::cout << "int=" << p1 << ", double=" << p2 << ", string=" << p3 << std::endl; return 1; } int g(int p1, std::string p2) { std::cout << "int=" << p1 << ", string=" << p2 << std::endl; return 2; } int main() { std::tuple<int, double, char const*> tup(1, 2.0, "xxx"); std::cout << apply(f, tup) << std::endl; std::cout << apply(g, std::make_tuple(4, "yyy")) << std::endl; } Remark: If I hardcode the return type in the recursive case (see code), then everything is fine. That is, substituting this snippet for the recursive case does not trigger the ICE: // Recursive case (hardcoded return type) template<unsigned int N> struct Apply_aux { template<typename F, typename T, typename... X> static int apply(F f, const T& t, X... x) { return Apply_aux<N-1>::apply(f, t, std::get<N-1>(t), x...); } }; Alas, this is an incomplete solution to the original problem.

    Read the article

  • Conflicting return types

    - by Adi
    I am doing a recursive program and I am getting an error about conflicting types: void* buddyMalloc(int req_size) { // Do something here return buddy_findout(original_index,req_size); // This is the recursive call } void *buddy_findout(int current_index,int req_size) { char *selected = NULL; if(front!=NULL) { if(current_index==original_index) { // Do something here return selected; } else { // Do Something here return buddy_findout(current_index+1,req_size); } } else { return buddy_findout(current_index-1,req_size); } } Error: buddy.c: At top level: buddy.c:76: error: conflicting types for ‘buddy_findout’ buddy.c:72: note: previous implicit declaration of ‘buddy_findout’ was here Please note the file buddy.c in which I am defining this does not contain main and is linked with several other .c files.

    Read the article

  • Create a triangle out of stars using only recursion

    - by Ramblingwood
    I need to to write a method that is called like printTriangle(5);. We need to create an iterative method and a recursive method (without ANY iteration). The output needs to look like this: * ** *** **** ***** This code works with the iterative but I can't adapt it to be recursive. public void printTriangle (int count) { int line = 1; while(line <= count) { for(int x = 1; x <= line; x++) { System.out.print("*"); } System.out.print("\n"); line++; } } I should not that you cannot use any class level variables or any external methods. Thanks.

    Read the article

  • conflicting types for a function return in C

    - by Adi
    Hi all, Here is my question : I am doing a recursive program and I am getting an error saying conflicting types: Code is : void* buddyMalloc(int req_size) { //Do something here// return buddy_findout(original_index,req_size); //This is the recursive fn I call// } void *buddy_findout(int current_index,int req_size) { char *selected = NULL; if(front!=NULL) { if(current_index==original_index) { //Do something here// return selected ; // } else { //Do Something here// return buddy_findout(current_index+1,req_size); } } else { return buddy_findout(current_index-1,req_size); } } In the above code , "I am getting error like : conflicting types of buddy_findout " Thanks for the help in advance aditya

    Read the article

  • heirarchial data from self referencing table in tree form

    - by Beta033
    Ii looks like this has been asked and answered in all the simple cases, excluding the one that i'm having trouble with. I've tried using a recursive CTE to generate this, however maybe a cursor would be better? or maybe a set of recursive functions will do the trick? Can this be done in a cte? consider the following table PrimaryKey ParentKey 1 NULL 2 1 3 6 4 7 5 2 6 1 7 NULL should yield PK 1 -2 --5 -6 --3 7 -4 where the number of - marks equal the depth, my primary difficulty is the ordering.

    Read the article

  • Parallel Processing Simulation in Javascript

    - by le_havre
    Hello, I'm new to JavaScript so forgive me for being a n00b. When there's intensive calculation required, it more than likely involves loops that are recursive or otherwise. Sometimes this may mean having am recursive loop that runs four functions and maybe each of those functions walks the entire DOM tree, read positions and do some math for collision detection or whatever. While the first function is walking the DOM tree, the next one will have to wait its for the first one to finish, and so forth. Instead of doing this, why not launch those loops-within-loops separately, outside the programs, and act on their calculations in another loop that runs slower because it isn't doing those calculations itself? Retarded or clever? Thanks in advance!

    Read the article

  • nodejs async.waterfall method

    - by user1513388
    Update 2 Complete code listing var request = require('request'); var cache = require('memory-cache'); var async = require('async'); var server = '172.16.221.190' var user = 'admin' var password ='Passw0rd' var dn ='\\VE\\Policy\\Objects' var jsonpayload = {"Username": user, "Password": password} async.waterfall([ //Get the API Key function(callback){ request.post({uri: 'http://' + server +'/sdk/authorize/', json: jsonpayload, headers: {'content_type': 'application/json'} }, function (e, r, body) { callback(null, body.APIKey); }) }, //List the credential objects function(apikey, callback){ var jsonpayload2 = {"ObjectDN": dn, "Recursive": true} request.post({uri: 'http://' + server +'/sdk/Config/enumerate?apikey=' + apikey, json: jsonpayload2, headers: {'content_type': 'application/json'} }, function (e, r, body) { var dns = []; for (var i = 0; i < body.Objects.length; i++) { dns.push({'name': body.Objects[i].Name, 'dn': body.Objects[i].DN}) } callback(null, dns, apikey); }) }, function(dns, apikey, callback){ // console.log(dns) var cb = []; for (var i = 0; i < dns.length; i++) { //Retrieve the credential var jsonpayload3 = {"CredentialPath": dns[i].dn, "Pattern": null, "Recursive": false} console.log(dns[i].dn) request.post({uri: 'http://' + server +'/sdk/credentials/retrieve?apikey=' + apikey, json: jsonpayload3, headers: {'content_type': 'application/json'} }, function (e, r, body) { // console.log(body) cb.push({'cl': body.Classname}) callback(null, cb, apikey); console.log(cb) }); } } ], function (err, result) { // console.log(result) // result now equals 'done' }); Update: I'm building a small application that needs to make multiple HTTP calls to a an external API and amalgamates the results into a single object or array. e.g. Connect to endpoint and get auth key - pass auth key to step 2 Connect to endpoint using auth key and get JSON results - create an object containing summary results and pass to step 3. Iterate over passed object summary results and call API for each item in the object to get detailed information for each summary line Create a single JSON data structure that contains the summary and detail information. The original question below outlines what I've tried so far! Original Question: Will the async.waterfall method support multiple callbacks? i.e. Iterate over an array thats passed from a previous item in the chain, then invoke multiple http requests each of which would have their own callbacks. e.g, sync.waterfall([ function(dns, key, callback){ var cb = []; for (var i = 0; i < dns.length; i++) { //Retrieve the credential var jsonpayload3 = {"Cred": dns[i].DN, "Pattern": null, "Recursive": false} console.log(dns[i].DN) request.post({uri: 'http://' + vedserver +'/api/cred/retrieve?apikey=' + key, json: jsonpayload3, headers: {'content_type': 'application/json'} }, function (e, r, body) { console.log(body) cb.push({'cl': body.Classname}) callback(null, cb, key); }); } }

    Read the article

  • Does the box API require case-sensitive booleans?

    - by Nick Chadwick
    I'm having some issues with the box.com developer API, and it seems that this is due to the API requiring lower-case booleans in request parameters. When I make a call to say, delete a folder, the URI my framework is generating looks like this: (DELETE) https://api.box.com/2.0/folders/1234?recursive=True This doesn't work, and the API throws an error. However, if I manually set the URI to this: (DELETE) https://api.box.com/2.0/folders/1234?recursive=true Everything seems to work just fine. I'd like to confirm that this is indeed the behavior, and if it is, I'd like to request box fix their API!

    Read the article

  • Counting vowels in a string using recursion

    - by Daniel Love Jr
    In my python class we are learning about recursion. I understand that it's when a function calls itself, however for this particular assignment I can't figure out how exactly to get my function to call it self to get the desired results. I need to simply count the vowels in the string given to the function. def recVowelCount(s): 'return the number of vowels in s using a recursive computation' vowelcount = 0 vowels = "aEiou".lower() if s[0] in vowels: vowelcount += 1 else: ??? I'm really not sure where to go with this, it's quite frustrating. I came up with this in the end, thanks to some insight from here. def recVowelCount(s): 'return the number of vowels in s using a recursive computation' vowels = "aeiouAEIOU" if s == "": return 0 elif s[0] in vowels: return 1 + recVowelCount(s[1:]) else: return 0 + recVowelCount(s[1:])

    Read the article

  • hierarchical data from self referencing table in tree form

    - by Beta033
    It looks like this has been asked and answered in all the simple cases, excluding the one that I'm having trouble with. I've tried using a recursive CTE to generate this; however maybe a cursor would be better? Or maybe a set of recursive functions will do the trick? Can this be done in a cte? consider the following table PrimaryKey ParentKey 1 NULL 2 1 3 6 4 7 5 2 6 1 7 NULL should yield PK 1 -2 --5 -6 --3 7 -4 where the number of - marks equal the depth, my primary difficulty is the ordering.

    Read the article

  • Generically creating objects in C#

    - by DrLazer
    What I am trying to do is load in objects from an XML save file. The problem is those objects are configurable by the user at runtime, meaning i had to use reflection to get the names and attributes of those objects stored in an XML file. I am in the middle of a recursive loop through the XML and up to the part where I need to create an object then thought ..... ah - no idea how to do that :( I have an array stuffed with empty objects (m_MenuDataTypes), one of each possible type. My recursive loading function looks like this private void LoadMenuData(XmlNode menuDataNode) { foreach (object menuDataObject in m_MenuDataTypes) { Type menuDataObjectType = menuDataObject.GetType(); if (menuDataObjectType.Name == menuDataNode.Name) { //create object } } } I need to put some code where my comment is but I can't have a big switch statement or anything. The objects in my array can change depending on how the user has configured the app.

    Read the article

  • Keeping track of threads when creating them recursively

    - by 66replica
    I'm currently working on some code for my Programming Languages course. I can't post the code but I'm permitted to talk about some high level concepts that I'm struggling with and receive input on them. Basically the code is a recursive DFS on a undirected graph that I'm supposed to convert to a concurrent program. My professor already specified that I should create my threads in the recursive DFS method and then join them in another method. Basically, I'm having trouble thinking of how I should keep track of the threads I'm creating so I can join all of them in the other method. I'm thinking an array of Threads but I'm unsure how to add each new thread to the array or even if that's the right direction.

    Read the article

  • movedown method not saving new position - cakephp tree

    - by Ryan
    Hi everyone, I am experiencing a problem that has popped up recently and is causing quite a bit of trouble for our system. The app we have relies on using the movedown method to organize content, but as of late it has stopped working and began to generate the following warning: Warning (2): array_values() [<a href='function.array-values'>function.array-values</a>]: The argument should be an array in [/usr/local/home/cake/cake_0_2_9/cake/libs/model/behaviors/tree.php, line 459] The line being referenced: list($node) = array_values($Model->find('first', array( 'conditions' => array($scope, $Model->escapeField() => $id), 'fields' => array($Model->primaryKey, $left, $right, $parent), 'recursive' => $recursive ))); The line calling the method: $this->movedown($id,abs((int)$position)); I have exhausted every idea I could come up with. Has anyone else crossed this issue before? Any help, or pointing in a direction would be much appreciated!

    Read the article

  • Dijkstra’s algorithm and functions

    - by baris_a
    Hi guys, the question is: suppose I have an input function like sin(2-cos(3*A/B)^2.5)+0.756*(C*D+3-B) specified with a BNF, I will parse input using recursive descent algorithm, and then how can I use or change Dijkstra’s algorithm to handle this given function? After parsing this input function, I need to execute it with variable inputs, where Dijkstra’s algorithm should do the work. Thanks in advance. EDIT: May be I should ask also: What is the best practice or data structure to represent given function?

    Read the article

  • Prevent image cropping when making sprites from gif

    - by OSaad
    Hey guys I've tried several tools (imagemagic, gif2png, Nconverter) to extract frames to make sprites from a .gif image that i have. I get the .pngs just fine, but they'r not the same size, some are 50x65 some 43x65 some 50x70, Which really screws any attempts at a descent animation. So is there a way to prevent this cropping or programmatically add extra transparent space to smaller ones and make them all the same size? Thanks.

    Read the article

  • Efficiently solving sparse matrices

    - by anon
    For solving spare matrices, in general, how big does the matrix have to be (as a rule of thumb) for methods like congraduate descent to be faster than brute force solvers (that do not take advantage o sparsity)?

    Read the article

  • Is this grammar SLR?

    - by Mike
    E - A | B A - a | c B - b | c My answer is no because it has a reduce/reduce conflict, can anyone else verify this? Also I gained my answer through constructing the transition diagram, is there a simpler way of finding this out? Thanks for the help! P.S Would a Recursive Descent be able to parse this?

    Read the article

  • When can Java produce a NaN (with specific code question)

    - by Brent
    I'm a bit perplexed by some code I'm currently writing. I am trying to preform a specific gradient descent (main loop included below) and depending on the initial conditions I will alternatively get good looking results (perhaps 20% of the time) or everything becomes NaN (the other 80% of the time). However it seems to me that none of the operations in my code could produce NaN's when given honest numbers! My main loop is: // calculate errors delta = m1 + m2 - M; eta = f1 + f2 - F; for (int i = 0; i < numChildren; i++) { epsilon[i] = p[i]*m1+(1-p[i])*m2+q[i]*f1+(1-q[i])*f2-C[i]; } // use errors in gradient descent // set aside differences for the p's and q's float mDiff = m1 - m2; float fDiff = f1 - f2; // first update m's and f's m1 -= rate*delta; m2 -= rate*delta; f1 -= rate*eta; f2 -= rate*eta; for (int i = 0; i < numChildren; i++) { m1 -= rate*epsilon[i]*p[i]; m2 -= rate*epsilon[i]*(1-p[i]); f1 -= rate*epsilon[i]*q[i]; f2 -= rate*epsilon[i]*(1-q[i]); } // now update the p's and q's for (int i = 0; i < numChildren; i++) { p[i] -= rate*epsilon[i]*mDiff; q[i] -= rate*epsilon[i]*fDiff; } This behavior can be seen when we have rate = 0.01; M = 30; F = 30; C = {15, 25, 35, 45}; with the p[i] and q[i] chosen randomly uniformly between 0 and 1, m1 and m2 chosen randomly uniformly to add to M, and f1 and f2 chosen randomly uniformly to add up to F. Does anyone see anything that could create these NaN's?

    Read the article

  • How to compile 'stygmorgan-0.29'?

    - by iwan
    I am trying to compile stygmorgan-0.29.tar.bz2 and got these messages: stygmorganui.cxx:7:28: fatal error: stygmicon128.xpm: No such file or directory compilation terminated. make[2]: *** [stygmorganui.o] Error 1 make[2]: Leaving directory `/home/papa/Downloads/stygmorgan-0.29/src' make[1]: *** [all] Error 2 make[1]: Leaving directory `/home/papa/Downloads/stygmorgan-0.29/src' make: *** [all-recursive] Error 1 papa@papa-G31-M7-TE:~/Downloads/stygmorgan-0.29$

    Read the article

  • Implement Negascout Algorithm with stack

    - by Dan
    I'm not familiar with how these stack exchange accounts work so if this is double posting I apologize. I asked the same thing on stackoverflow. I have added an AI routine to a game I am working on using the Negascout algorithm. It works great, but when I set a higher maximum depth it can take a few seconds to complete. The problem is it blocks the main thread, and the framework I am using does not have a way to deal with multi-threading properly across platforms. So I am trying to change this routine from recursively calling itself, to just managing a stack (vector) so that I can progress through the routine at a controlled pace and not lock up the application while the AI is thinking. I am getting hung up on the second recursive call in the loop. It relies on a returned value from the first call, so I don't know how to add these to a stack. My Working c++ Recursive Code: MoveScore abNegascout(vector<vector<char> > &board, int ply, int alpha, int beta, char piece) { if (ply==mMaxPly) { return MoveScore(evaluation.evaluateBoard(board, piece, oppPiece)); } int currentScore; int bestScore = -INFINITY; MoveCoord bestMove; int adaptiveBeta = beta; vector<MoveCoord> moveList = evaluation.genPriorityMoves(board, piece, findValidMove(board, piece, false)); if (moveList.empty()) { return MoveScore(bestScore); } bestMove = moveList[0]; for(int i=0;i<moveList.size();i++) { MoveCoord move = moveList[i]; vector<vector<char> > newBoard; newBoard.insert( newBoard.end(), board.begin(), board.end() ); effectMove(newBoard, piece, move.getRow(), move.getCol()); // First Call ****** MoveScore current = abNegascout(newBoard, ply+1, -adaptiveBeta, -max(alpha,bestScore), oppPiece); currentScore = - current.getScore(); if (currentScore>bestScore){ if (adaptiveBeta == beta || ply>=(mMaxPly-2)){ bestScore = currentScore; bestMove = move; }else { // Second Call ****** current = abNegascout(newBoard, ply+1, -beta, -currentScore, oppPiece); bestScore = - current.getScore(); bestMove = move; } if(bestScore>=beta){ return MoveScore(bestMove,bestScore); } adaptiveBeta = max(alpha, bestScore) + 1; } } return MoveScore(bestMove,bestScore); } If someone can please help by explaining how to get this to work with a simple stack. Example code would be much appreciated. While c++ would be perfect, any language that demonstrates how would be great. Thank You.

    Read the article

< Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >