We’re rewarding the question askers & reputations are being recalculated! Read more.

# Tag Info

25

I would use some template logic to achieve the affect in a more scalable way: #include <iostream> #include <sstream> #include <string> #include <algorithm> // This is the type that will hold all the strings. // Each enumeration type will declare its own specialization. // Any enum that does not have a specialization will generate a ...

13

I would follow the way user-defined literals are used in the C++14 standard library: put them in a literals subnamespace that can be imported by the user. This subnamespace would be inline so that it can be imported alone, or automatically imorted when the namescape net is imported: namespace net { class uri { ... }; // contains decomposed URI (path, ...

8

Overall Not sure I agree with the use of std::unique_ptr inside of Node. BUT I can't really argue against it. So I am not going to push the point. You need to concentrate on your const correctness. Design Using a linked list for a stack seems very inefficient way of doing this. Each object that you save required an additional pointer. In this case were ...

7

Namespaces At least in my experience, dislike for the std:: prefix all over the place is largely a matter of what you're accustomed to seeing. When namespaces were new, I found it quite jarring and off-putting. 20 years (or so) later, I generally prefer code that includes it (though some might argue that this is just a strange case of Stockholm syndrome). ...

7

I'll assume that you've read Why is using namespace std considered bad practice? so you understand the reasons that this can cause problems for your code. I'm not going to address that any further in this answer. You have alternatives, that reduce the risk compared to using namespace std; at file scope: Selectively import names you're going to use, in the ...

6

In most cases, the requirement of converting between c++ enumeration and string representation arises from interfacing to another program that does not understand your enumeration declarations. Often this other program will be a SQL database. Hence I would go for a code generator to ensure consistency over the whole system. The code generator could walk ...

6

Your header file is missing include guards. Either put #pragma once at the start, or use the more portable: #ifndef MESH_H_ #define MESH_H_ // ... rest of header #endif MESH_H_ has to be unique for the file. namespace OpenGL{ If you don't own OpenGL, I'd recommend not naming your namespace after it. If they release OpenGL in a namespace, your code ...

6

swap does not swap sizes. If pop_back throws on empty stack, top shall also throw. I see no reason for an operator<< to build a string. os << '|' << std::to_string(current->data()) << '|\n'; in a loop achieves the same result. I would also consider letting Node to output itself with Node::operator<<.

5

Using a range-based for loop makes the loop much easier to read #include <iostream> #include <vector> int main() { std::string text; std::vector<std::string> vector; while(std::cin >> text) vector.push_back(text); for (const auto& value : vector) { std::cout << value << ' ' << ...

5

My thoughts: Imho Database should not belong to Utilities namespace. Working with database is likely a core part of your application, "Utilities" suggest auxiliary tools to make your life easier. But maybe the class does something different than I expect Is there a reason to keep all your application in Metin2 namespace but have separate Exceptions ...

5

Lets look at a couple of improvements: new is creating an object that you aren't using. read edit for clarification new window.APP_NAME.moduleName.functionInsideModule1({ name: 'Mary' }); The function functionInsideModule1 doesn't return an object and doesn't assign anything to this. So there is no need for the new. You're referencing the whole ...

5

I've worked for a media company where ads had to run with their own version of JavaScript libraries, in the end we preferred to let ads run in their own iframe. Especially since some ads required access to document.write which creates havoc to your content ;) It is a bit scary that your solution has to modify jquery-ui.js, I would be very (very) hesitant to ...

5

Personally, I'd prefer to use @export() or @export(globals()), rather than manually perform the @ sugar. I don't like using __globals__, even if it is writeable. Honestly, I think the cleanest solution would be to abuse lists, and use a closure. I do however agree that inheriting from Exception, is the best parent to inherit from. And so I'd personally use ...

4

Extract the common logic to a function, where the varying parts are parameters. Unless I'm missing something, this looks trivially easy to do: function setup_namespace(org_id) { var nsp = io.of('/nsp_bucket_' + org_id); nsp.on('connection', function(socket){ console.log('someone connected to namespace bucket ' + org_id); socket.on('...

4

Here is a template class that enables writing and reading enum class members as strings. It is a simplification of Loki Astari's design. It avoids the need for helper functions, as suggested by Veski, by using the enable_if<> and is_enum<> templates. The idea is to replace template <T> with template <typename T, typename std::...

4

Well, the first thing I'd do is put the patterns in a list, and loop through matching them. The second thing would be general cleanup; use namespaces where you can, one-liner if/else clauses don't need braces, use var where the type is obvious, etc etc. This gets rid of that if-elseif structure and makes the code much more concise. As far as merging the ...

4

From a once over: In the below block, you can assume that if window.APP_NAME exists, that deepExtend is assigned, and if it did not exist, then obviously deepExtend is not assigned. So I would do this: window.APP_NAME = window.APP_NAME || { deepExtend : deepExtend = function (destination, source) { for (var property in source) { ...

4

I don't like this approach. The biggest issue I have with this code is the fact that namespaces are attached to every lookup. Beyond being a bit long and awkward, it's hard to see the difference between two very similar looking symbol names when they start in exactly the same fashion. This is especially important when dealing with constructors, which are ...

4

Background task handling You must wait for the child process regardless of how it is started, in the background or not. As written, a background command ends up in the zombie state. To let the parent shell to continue, set up a signal handler for SIGCHLD, and wait there. I know the program statement doesn't require it, but it always nice to let user query ...

3

SO your issue is that this is not as readable: for(std::vector<std::string>::size_type i = 0; i < svec.size(); i++) std::cout << svec[i] + " " << svec[i].size() << "\n"; Well I disagree with that. BUT there are also better ways to write that: for(auto const& item: svec.size()) { std::cout << item + " " <&...

3

LinkedList Header Don't use identifiers with a leading underscore: #ifndef _NEW_LL_H #define _NEW_LL_H These two are not valid (reserved for the implementation). Header inclusion order: #include<memory> #include "node.h" I always do most specific to least. So your local header files first. Then C++ header files. Then C header files. Also add a ...

3

To your question ( confirmed by the comments ), you are not polluting the namespace because you are Wrapping already inside \$(document).ready(function() { Using var for every variable. Furthermore, from what I can see that is left over from rotator, it was probably a better approach than what you have now. From a once over: Spelling is important: ...

3

I don't see the point in trying to use using (even in this protected situation). // 26 letters using std::runtime_error; // later (saved 5 characters (so you need to use it 6 times to save typing)). throw runtime_error("Message"); // Also it makes it harder for the reader. I am going to ask where is // the definition of runtime_error (and then search to ...

3

class Node { private: int m_data; std::unique_ptr<Node> m_previous; public: Node(int data, std::unique_ptr<Node>& previous) { m_data = data; m_previous = std::move(previous); } Since Node is an implementation detail of Stack, you don't need to hide Nodes members data and previous from Stack. Consider ...

2

I am going to assume you are using Python's built-in XML library. There are some basic XPath functionality implemented into Python's XML library. Using XPath and the find() function: import xml.etree.ElementTree as ElementTree namespace = '{urn:schemas-upnp-org:device-1-0}' root = ElementTree.fromstring(urllib2.urlopen(XMLLocation).read()) # The // ...

2

As far as experience goes, what my team does is to actually agree on a single version of a library and stick to it for the entire production release. That way, each developer will not encounter bugs due to differences. We then talk about upgrades in a meeting to agree on the next version to support, then test the switch for any bugs that old code might ...

2

Avoid a hacker exploit. The null character is not special when fgets() reads it. So if the first character read is the rare null character, then input[strlen(input) - 1] is UB. strcspn() is a nice alternative. if (!fgets(input, sizeof(input), stdin)) break; //if (input[strlen(input) - 1] == '\n') // input[strlen(input) - 1] = '\0'; input[strcspn(input,...

2

Given your sample data, this is what I could come up with off the cuff. While likely not an optimal solution, it should be a step in the right direction and I'm sure you can take it from here. I also made some assumptions about nullity since this wasn't explicitly provided in your sample set. You may be able to thus trim down or modify the ...

2

No love for typedefs? typedef std::vector<std::string> MyVec; typedef std::map<std::string, std::vector<std::set<std::string> > > CrazyContainer; ... for(MyVec::size_type i = 0; i < svec.size(); i++) std::cout << svec[i] + " " << svec[i].size() << "\n"; // Or for C++11 using MyVec = std::vector&...

Only top voted, non community-wiki answers of a minimum length are eligible