• What Do You Need Help With? V8
    1,074 replies, posted
[QUOTE=Proclivitas;52968523]You want everything to be asynchronous if possible to maximize concurrency and system resources.[/QUOTE] Yeah I understand why async might be useful. But this endpoint is only getting a database record by id. Not really super intensive work there...
[QUOTE=brianosaur;52969332]Yeah I understand why async might be useful. But this endpoint is only getting a database record by id. Not really super intensive work there...[/QUOTE] Like I said, .Net Core only exposes async methods for Azure Table
[QUOTE=brianosaur;52969332]Yeah I understand why async might be useful. But this endpoint is only getting a database record by id. Not really super intensive work there...[/QUOTE] Asynchronous methods aren't just helpful when it comes to the amount of work. I came across [url=http://www.tugberkugurlu.com/archive/how-and-where-concurrent-asynchronous-io-with-asp-net-web-api]a very helpful article[/url] that benchmarks the performance between the different methods of synchronous and asynchronous methods.
[QUOTE=brianosaur;52969332]Yeah I understand why async might be useful. But this endpoint is only getting a database record by id. Not really super intensive work there...[/QUOTE] Imagine having a OS thread receiving web requests on a web server. That OS thread then services your GET for ID 1. It then sends out an IO request to a database server or another web service and it will be a 100ms round trip. That OS thread sending that request probably takes 1ms-2ms at MOST/WORST case. Instead of 1 thread being able to service 500-1000 requests within a second, you need 500-1000 threads to sit and service and ACTIVELY wait on those requests. You are literally never going to scale. When asynchronous programming is so easy, there is no reason you shouldn't be asynchronous from the start. You aren't doing multi-threading parallelism, you are doing asynchronous concurrency.
[QUOTE=proboardslol;52969378]Like I said, .Net Core only exposes async methods for Azure Table[/QUOTE] Right, that's why I asked if there was some requirement to using it because the obvious answer seemed to be to just not use async. Not sure what you have tried or even figured it out, but maybe you need to inherit your controller class from AsyncController instead of Controller? see: [url]https://stackoverflow.com/questions/20221603/task-async-controller-method-does-not-hit[/url] [QUOTE=horsedrowner;52969658]Asynchronous methods aren't just helpful when it comes to the amount of work. I came across [url=http://www.tugberkugurlu.com/archive/how-and-where-concurrent-asynchronous-io-with-asp-net-web-api]a very helpful article[/url] that benchmarks the performance between the different methods of synchronous and asynchronous methods.[/QUOTE] I gotcha, you can also upgrade your infrastructure to handle more requests concurrently. I just personally don't like the idea using the async framework features unless it's really needed because it leads to more complex code and harder to understand, and thus, harder to debug
[QUOTE=brianosaur;52970285] I gotcha, you can also upgrade your infrastructure to handle more requests concurrently. I just personally don't like the idea using the async framework features unless it's really needed because it leads to more complex code and harder to understand, and thus, harder to debug[/QUOTE] I would actually argue the opposite. If you use async/await properly, you signal which functions are expensive and which are not (relatively speaking, of course). Kind of like using methods instead of properties. As an example, consider IQueryable. The System.Data.Entity namespace contains Async overloads for all of the methods that execute the query, and none of those that execute on the client. There's CountAsync, but no WhereAsync. There's definitely some sort of complexity involved, though. At a glance, it seems simple ("just add async and await") but when you start looking into how it works, it becomes complex and difficult to understand.
So I'm at work right now and we have been experiencing some shitty download speeds on large files. Fast.com says we're getting 70mbps which is the tier we're on and all of the small packet functions we do seem fine but large downloads rarely reach above 2mb/s. Is this the fault of the remote server or should I be checking my firewall/router for throttling settings?
[QUOTE=horsedrowner;52970375]I would actually argue the opposite. If you use async/await properly, you signal which functions are expensive and which are not (relatively speaking, of course). Kind of like using methods instead of properties. As an example, consider IQueryable. The System.Data.Entity namespace contains Async overloads for all of the methods that execute the query, and none of those that execute on the client. There's CountAsync, but no WhereAsync. There's definitely some sort of complexity involved, though. At a glance, it seems simple ("just add async and await") but when you start looking into how it works, it becomes complex and difficult to understand.[/QUOTE] Async/await makes the user facing code slightly more complicated because most people do not spend a day researching it in my opinion. If delve into it and realize how it works under the covers and understand [URL="https://docs.microsoft.com/en-us/dotnet/api/system.threading.synchronizationcontext?view=netframework-4.7.1"]SynchronizationContext[/URL], [URL="https://msdn.microsoft.com/en-us/library/windows/desktop/aa365198(v=vs.85).aspx"]IO Completion Ports[/URL], and what the IL looks like after the transformations, you are able to reason about your code pretty easily. [URL="https://blog.stephencleary.com/"]Stephen Cleary[/URL] has a great series of blog posts where he dives deep into Async/Await, .NET TPL, and threading in general. Specifically these two, [URL="https://blog.stephencleary.com/2012/02/async-and-await.html"]async and await[/URL] and [URL="https://blog.stephencleary.com/2013/11/there-is-no-thread.html"]there is no thread[/URL]. All new code should be asynchronous in my opinion, it is too easy to not write asynchronous code in .NET whether in a Desktop application, a Windows service, or in ASP.NET.
I figured out the solution to my problem. Earlier in here I posted about how I was trying to do asset sharing across multiple OpenGL contexts. I had an issue where it appeared that I was successfully creating texture objects in a separate thread in a different context, as the ID's were incrementing appropriately across the 2 threads, however the textures weren't being sampled from at all. I dug into the spec for [URL="https://www.khronos.org/registry/OpenGL/extensions/NV/NV_bindless_texture.txt"]bindless textures[/URL], and fortunately I found that bindless textures creation and sharing [B]is supported[/B] across multiple contexts. The same handle works across all of the contexts in the share-group. However, texture residency [B]isn't[/B] automatic across the share-group:eng101: I don't yet have a smart system for dealing with texture residency; rather I just make them all resident as soon as they are created (which in my case, was in the secondary context) Therefore the solution was just to make that same handle resident in the main rendering thread. Edit: Aw man, I didn't know vertex array objects can't do this either. The vertex buffers can be shared but the array object can't. I'm going to have to rethink the layout of some of my systems.
I almost over-engineered a solution to that problem too, luckily I waited and (very last minute) figured out a much more elegant solution. I was prepared to write out an entire third class to manage VAO handles per context, using a singleton class and a map of vectors storing VAO's. And then I realized that: sure, models are generic and deprived of state, but the components that use them are unique per engine instance; they can just generate their own vertex array objects to encapsulate the model they've requested. I can't believe it took me this long to realize this - I would have almost made a horrible horrible mess of my code.
I'm working on raycasting, and am currently on floorcasting. I read that you just get the pixels of the floor that your initial ray intersects, and I did that but it's REALLY slow Here's an example (with some of the trigonometry a bit off) [url]http://104.207.128.112/games/ray/[/url] I'm not totally understanding any of the tutorials I'm reading either. Can someone help?
What's peoples opinion on learning C these days? I've been trying to learn programming for a while and have shifted between C++, Java, C# and Python a few times. I've picked up the basic concepts and can confidently write simple programs in most of them but I'm still not far enough to make anything of value. C# has been the one I've tried the most but I always get kinda unmotivated after a while since I don't understand why I'm using a lot of the tools I use or how they work. All I know is that I can apply them to some situations and have it work. Would learning C be different? As far as I know, C is a lot simpler in terms of how many tools are available to you but harder because you have to make a lot of stuff that is already prepackaged with other languages. I'm hoping that C will make me understand why and how it all works so I can get a better understanding of why I'm doing it the way I'm doing it. Though I did read that trying to understand the why and how of everything isn't a feasible task simply because computers have gotten so complex that a single human can't realistically understand all of it. It pains me to use C# tho because I don't feel like I'm really "programming" when all I'm doing is using stuff in libraries and getting it to work together. Ultimately I want to understand how to manipulate other programs directly through memory and I think C and C++ are more suitable candidates for that than say C#. I'm just worried that trying to learn either of those without being able to confidently write programs that do anything meaningful in something like C# will just end up with me getting frustrated
[QUOTE=PredGD;52983677]What's peoples opinion on learning C these days? I've been trying to learn programming for a while and have shifted between C++, Java, C# and Python a few times. I've picked up the basic concepts and can confidently write simple programs in most of them but I'm still not far enough to make anything of value. C# has been the one I've tried the most but I always get kinda unmotivated after a while since I don't understand why I'm using a lot of the tools I use or how they work. All I know is that I can apply them to some situations and have it work. Would learning C be different? As far as I know, C is a lot simpler in terms of how many tools are available to you but harder because you have to make a lot of stuff that is already prepackaged with other languages. I'm hoping that C will make me understand why and how it all works so I can get a better understanding of why I'm doing it the way I'm doing it. Though I did read that trying to understand the why and how of everything isn't a feasible task simply because computers have gotten so complex that a single human can't realistically understand all of it. It pains me to use C# tho because I don't feel like I'm really "programming" when all I'm doing is using stuff in libraries and getting it to work together. Ultimately I want to understand how to manipulate other programs directly through memory and I think C and C++ are more suitable candidates for that than say C#. I'm just worried that trying to learn either of those without being able to confidently write programs that do anything meaningful in something like C# will just end up with me getting frustrated[/QUOTE] There's nothing wrong with just using libraries and mixing stuff together. I'd say that a pretty small fraction of my job is writing outright "new" code or systems, and a lot of it synthesizing what I find online, in libraries, and on github together into what I need. I think C is too low-level to be useful for most people tbh, outside of embedded. You have to consider Dev time, and the utilities the language offers - C isn't bad, and its got good things going for it. But it lacks simple things that you [I]really[/I] miss after using something like C++/C#: constructors, destructors, not making everything callbacks, more modern abstractions for things, and a less-than-sparse standard library. C has its place, by all means, but its not something that will fit most people very well. If you want to learn C++, get something like "C++ Primer, 5th Ed." and give it a read-through. It starts really basic and builds up, and uses the newer features of C++11 while still at least briefly covering the old way of doing things (and explaining why the newer way is nicer). Ultimately, whats going to help the most in learning is finding a project that interests you and that you want to work on. Transcribing code in the beginning is also helpful.
[QUOTE=paindoc;52984053]There's nothing wrong with just using libraries and mixing stuff together. I'd say that a pretty small fraction of my job is writing outright "new" code or systems, and a lot of it synthesizing what I find online, in libraries, and on github together into what I need. I think C is too low-level to be useful for most people tbh, outside of embedded. You have to consider Dev time, and the utilities the language offers - C isn't bad, and its got good things going for it. But it lacks simple things that you [I]really[/I] miss after using something like C++/C#: constructors, destructors, not making everything callbacks, more modern abstractions for things, and a less-than-sparse standard library. C has its place, by all means, but its not something that will fit most people very well. If you want to learn C++, get something like "C++ Primer, 5th Ed." and give it a read-through. It starts really basic and builds up, and uses the newer features of C++11 while still at least briefly covering the old way of doing things (and explaining why the newer way is nicer). Ultimately, whats going to help the most in learning is finding a project that interests you and that you want to work on. Transcribing code in the beginning is also helpful.[/QUOTE] I think I'll pick C++ over C for the reasons you mentioned. I have no interest in embedded platforms as of now and it sounds frustrating to make the things I want to make in C. Regarding reverse engineering and code manipulation, I imagine C++ is still a solid choice? I'm not sure if there's a language that is more suited for it but I'm thinking that its a big benefit of communicating more directly with the hardware than through a virtual machine in regards to that.
[QUOTE=PredGD;52983677]C# has been the one I've tried the most but I always get kinda unmotivated after a while since I don't understand why I'm using a lot of the tools I use or how they work. All I know is that I can apply them to some situations and have it work.[/QUOTE] It's a little vague, but simply experiment with and try to look into how something works behind the scenes. This has helped me personally a lot in understanding the 'magic' behind certain parts of C#. Async/await, for example, has always seemed like magic until I've read articles and blog posts about the underlying implementation. For another example, Entity Framework is a fantastic and relatively easy to pick up library, but being able to translate code into SQL queries seems like magic until you look into Linq expressions and play around with them. Hell, I still discover things about tools and libraries I've used for years, simply by running into new problems and figuring out what caused them. Of course, a lot of it has to do with experience as well. You won't understand the intricate workings of something immediately after using it for the first time. [QUOTE=PredGD;52983677]It pains me to use C# tho because I don't feel like I'm really "programming" when all I'm doing is using stuff in libraries and getting it to work together.[/QUOTE] I understand your feelings on this part but like others have said, this is pretty normal. There's definitely value in "re-inventing the wheel" for the purposes of learning how things work. However when it comes to writing non-trivial applications, it's very impractical to write everything yourself. This becomes more evident the larger/more complex the library or framework you're consuming (see my earlier point about 'magic').
[QUOTE=PredGD;52983677]What's peoples opinion on learning C these days? I've been trying to learn programming for a while and have shifted between C++, Java, C# and Python a few times. I've picked up the basic concepts and can confidently write simple programs in most of them but I'm still not far enough to make anything of value. C# has been the one I've tried the most but I always get kinda unmotivated after a while since I don't understand why I'm using a lot of the tools I use or how they work. All I know is that I can apply them to some situations and have it work. Would learning C be different? As far as I know, C is a lot simpler in terms of how many tools are available to you but harder because you have to make a lot of stuff that is already prepackaged with other languages. I'm hoping that C will make me understand why and how it all works so I can get a better understanding of why I'm doing it the way I'm doing it. Though I did read that trying to understand the why and how of everything isn't a feasible task simply because computers have gotten so complex that a single human can't realistically understand all of it. It pains me to use C# tho because I don't feel like I'm really "programming" when all I'm doing is using stuff in libraries and getting it to work together. Ultimately I want to understand how to manipulate other programs directly through memory and I think C and C++ are more suitable candidates for that than say C#. I'm just worried that trying to learn either of those without being able to confidently write programs that do anything meaningful in something like C# will just end up with me getting frustrated[/QUOTE] I feel like learning C made me understand how a computer really works
[QUOTE=PredGD;52984088]I think I'll pick C++ over C for the reasons you mentioned. I have no interest in embedded platforms as of now and it sounds frustrating to make the things I want to make in C. Regarding reverse engineering and code manipulation, I imagine C++ is still a solid choice? I'm not sure if there's a language that is more suited for it but I'm thinking that its a big benefit of communicating more directly with the hardware than through a virtual machine in regards to that.[/QUOTE] From personal experience with C, C++, Java, Python, and write a few other languages, I can say that I've sort of fallen out of using C/C++ because of the hassle of memory management and other smaller issues like array/list/vector/map/hashtable functions. I feel like there's a lot of time wasted just trying to handle these things when higher level langauges do it pretty much automatically. I agree with proboardslol though, learning C/C++ made me understand all the underlying mechanics of programming. I definitely learned so much from those langauges, but I don't think it's worth using for new programs.
[QUOTE=horsedrowner;52984341]It's a little vague, but simply experiment with and try to look into how something works behind the scenes. This has helped me personally a lot in understanding the 'magic' behind certain parts of C#. Async/await, for example, has always seemed like magic until I've read articles and blog posts about the underlying implementation. For another example, Entity Framework is a fantastic and relatively easy to pick up library, but being able to translate code into SQL queries seems like magic until you look into Linq expressions and play around with them. Hell, I still discover things about tools and libraries I've used for years, simply by running into new problems and figuring out what caused them. Of course, a lot of it has to do with experience as well. You won't understand the intricate workings of something immediately after using it for the first time. I understand your feelings on this part but like others have said, this is pretty normal. There's definitely value in "re-inventing the wheel" for the purposes of learning how things work. However when it comes to writing non-trivial applications, it's very impractical to write everything yourself. This becomes more evident the larger/more complex the library or framework you're consuming (see my earlier point about 'magic').[/QUOTE] To add to this, I've honestly found transcribing code to be immensely useful into understand [I]how[/I] the language is used, which is a bit more advanced than what most books can teach: they'll show your the ropes, the syntax, and offer usage examples and tips but its rare they manage to show you how to combine all of these disparate elements you've learned into something. I did this with a few open-source repositories when I was building my slice engine: much of that projects code is based on theirs, but I've replaced, improved, and refactored it as I've continued to learn more. What started as not entirely my own code has now become mostly my own code - even if it started as nearly directly-transcribed. Also reinventing the wheel depends on what you want to do - if you enjoy the idea of building a library and working on this kind of systems programming, it can be an educational experience in and of itself. Just don't be afraid, in the slightest, of borrowing lessons from others by using external libraries to guide and improve your own code (or to show you what you want to avoid). Building my Vulkan renderer and scenekit system has been a lot of work, and there are libraries out there doing that already: but I feel much better at this kind of coding after working on the two projects for 12+ months, respectively [QUOTE=huntingrifle;52985123]From personal experience with C, C++, Java, Python, and write a few other languages, I can say that I've sort of fallen out of using C/C++ because of the hassle of memory management and other smaller issues like array/list/vector/map/hashtable functions. I feel like there's a lot of time wasted just trying to handle these things when higher level langauges do it pretty much automatically. I agree with proboardslol though, learning C/C++ made me understand all the underlying mechanics of programming. I definitely learned so much from those langauges, but I don't think it's worth using for new programs.[/QUOTE] I agree/disagree, because I still use Python at work quite a bit for plotting data that my C++ astrodynamics toolkit spits out BUT, did you C++11/14/17? As much as modern C++ gets thrown out like a buzzword (up there with Machine Learning), it's really a night and day difference that can free the language from so much of the baggage that was holding it back and making it painful to use. Ultimately, though, its good to know a few languages. They're just tools in a toolbox, and knowing what language to use when is far more important than trying to find the best language or become perfect in any language. That and practicing. Doesn't really matter what, but if you can make it interesting to you that's a good thing. I only started programming in C++ last August - but I'd program for six hours at work then come home and program 6+ hours more on personal projects until I had to sleep. That and I tried to seek criticism, textbooks to read, and ways to keep myself inspired. Now I feel pretty damn good at C++ tbh (though I still have [i]loads[/i] to learn, I'm at least competent). I don't think you need to burn as hard as I did to become good or anything, but my point was that it was just the hours I put in that gave me what I have skills-wise today [sp]this long-ass post sponsored by not wanting to deal with obscure (and unfixed as of yet) bugs between clangs headers and libstdc++'s implementation, woooo[/sp]
Guys I have a problem thats been driving me up the wall for the past week. I doubt its going to be magically solved here but im all ears for suggestions at this point. Im currently working on automated testing for a company that does web applications, before coming here the stuff they had going was extremely non-scalable and since fixing that I have run into problems with only having limited machines to run these tests on (since what we use is terrible in that it cannot run multiple instances at once and to avoid local issue we don't want to run on local docker containers) The program for testing that we use has the capacity to handle remote execution and stores all HTML elements a test will use as strings that refer to their find expression, these elements are created from tests and then a dynamic pages file is made based on what tests are compiled. [b]The issue[/b] So what happens right now (which is by design because fuck knows why) is that if I have tests which cross reference elements created in other tests, when the files are uploaded to the remote machine it will attempt to compile the project there, but will not have all of the elements it requires and will crash. There is no way within the test framework or program to specify that you want everything uploaded regardless of use or to build the project BEFORE uploading it to the remote (as confirmed with the people who made this software) What perplexes me is that there was a single AWS instance here when I was first employed that this issue is not present on. You can upload a test that never even specifies its own elements and just uses others and it will run fine but try and do that on anything else, even the local VM's I use, and it will fail to compile. There does not seem to be anything special about this AWS instance compared to the other two we have, all of them are configured the same and require an SSH tunnel to a parent node for a remote connection to be established. If I had to try and fix this problem myself, I would probably try and add a listener/interceptor that when a remote execution is triggered, pulls the latest project files from git and puts them where the temporary uploaded files would be so the entire project is there for it to compile with but this does not appear to be what it is doing. My only other idea is that it is somehow targeting the host PC's files when it compiles due to the SSH tunnel connecting the localhost of the parent node to that of the machine here but I'm honestly unsure how you'd even go about doing that. I know its obviously difficult to answer something like this with such little information but does anyone have any clue how they might try and go about implementing a solution that may be how whoever set this up did?
I started programming months ago for university, so my problem could be basic, but anyway here it is I have to write a Java program that takes the user input and turns it into a descending staircase, like so: input: 4 2 6 1 3 3 output: [t]https://i.imgur.com/L24AaO1.png[/t] I've no idea how to do it
[QUOTE=SebiWarrior;52989361]I started programming months ago for university, so my problem could be basic, but anyway here it is I have to write a Java program that takes the user input and turns it into a descending staircase, like so: input: 4 2 6 1 3 3 output: [t]https://i.imgur.com/L24AaO1.png[/t] I've no idea how to do it[/QUOTE] You can break the problem down into 1) parsing the input into individual numbers, 2) working out what to output for horizontal parts of the stairs, then 3) working out what to output for the vertical parts. I'm guessing you are writing the output to System.out, so you'll be outputting the text from left to right for each line. Which of those parts are you struggling with specifically?
[QUOTE=Ziks;52989388]You can break the problem down into 1) parsing the input into individual numbers, 2) working out what to output for horizontal parts of the stairs, then 3) working out what to output for the vertical parts. I'm guessing you are writing the output to System.out, so you'll be outputting the text from left to right for each line. Which of those parts are you struggling with specifically?[/QUOTE] I've tried looking on the web for ways to turn the int value to an undefined sequence of characters to no avail
[QUOTE=SebiWarrior;52989509]I've tried looking on the web for ways to turn the int value to an undefined sequence of characters to no avail[/QUOTE] Just use a for-loop that runs [B]int[/B] number of times and appends a character to the string each time. Precede each loop with [B]x[/B] spaces so that it has the horizontal shift, and increment x every time you add a horizontal dash.
Is there any way to debug steamworks when working with the "server side" aspect of it? (as in game server, not steamworks itself) I'm using Facepunch.Steamworks and i keep getting this error: [code]InitServer: GameServer_Init returned false[/code] It seems no matter what parameters i use i get the same result. I've copied these files to the same directory as the exe: [IMG]https://u.x64.re/f/wMcn3d.png[/IMG] The console in Steam doesn't print anything. I assume that's because it's not client related? [editline]19th December 2017[/editline] There's not much code to show really. It doesn't work with the same code as the example/tests in the github repository for Facepunch.Steamworks. [editline].[/editline] I fixed it by recreating the project. Exact same code and dependencies/copied files. I don't even. :v: Oh well, it works now.
I've got a really weird performance issue in my work program, and it's not responding to anything I thought might've fixed it. Over time, my program takes more and more time to perform a timestep. The following program shows the wall-clock time taken to perform two steps (oops, bad label) during a 4000-second long sim-time run: [t]https://i.imgur.com/PDdNZPe.png[/t] I've done the following: - Checked for memory leaks, there are none. Memory usage increases slightly though due to me collecting data on ~12 satellite-like elements into 12 string streams sooooo - I made sure to give the string streams a big output buffer, since MSVC defaults to a small one, and disabled 11/12 output streams. No effect, but memory usage (of course) doesn't slowly increase (it peaks at about 200mb, but that makes sense given how much data im logging) - I've done lots and lots of profiling, which hasn't really given me any hints. I need to check more carefully for where the CPU is spending time the most as time goes on, but I'm running out of ideas. This is just the weirdest problem I've experienced, so I'm guessing its something either obvious or really esoteric. Given the age of this codebase, and how much of it is in a bad state (I need more time to fix it D:), I'm not going to dismiss the chances that it's something really bad happening in a corner of the code I've not yet cleaned up. [editline]20th December 2017[/editline] I've also tried what this thread mentioned, which is running without a debugger via powershell - that's what made the plot above [url]https://stackoverflow.com/questions/14617645/c-code-is-running-slower-over-time[/url] [editline]20th December 2017[/editline] oh, and at first I thought it might be like my integrator/propagator just getting to tiny tiny steps due to how its adaptive timestepping works. But this isn't the case either, as I'm currently forcing it to use constant-size timesteps. But once this performance bug hits, things seem to explode and go haywire in the simulation too. its fucking [I]bizarre[/I] [editline]20th December 2017[/editline] tamschi has pointed out it might be floating point denormal issues, which makes sense given past issues ive had and how the precision for this stuff has been a test so far (to say the least)
Anyone have experience with Minecraft here? I help a friend from time to time doing some plugin customization and what not. He recently asked me to see if I could do dualwielding. Now, as far as I can tell the Spigot API doens't support this in any way, which likely means I'll have to mod the game in some fashion. Any advice or insight?
So I just found out about variadic parameters/templates in c++ and haven't quite figured all the ways I can use them. I want to create a templated function that will be responsible for creating an object of the templated type, but take in a variable number of arguments and supply them to the objects' constructor. Along the lines of this: [code] struct foo { foo(int a) {} }; struct bar { bar(double a, bool b, float c) {} }; template<typename T> void do_thing( ... ) { va_list args; T t = T( CONVERT ARGS INTO USEABLE ARGS ); } // Usage do_thing<foo>( 99 ); do_thing<bar>( 32.0, false, 123.456f ); [/code] Is such a thing even possible? I remember that the thread object takes in its constructor a function pointer, and a variable number of arguments, and seems to call the function with the arguments in a similar fashion. [editline]21st December 2017[/editline] I figured it out. I dove into the header for std::thread and mimicked how it sent the arguments to the supplied function. For sake of completeness, here's a modified version of the above function which works: [code] template <typename T, class... _Args> void do_thing(_Args&&... _Ax) { T t = T( forward<_Args>(_Ax)... ); }[/code]
[QUOTE=Karmah;52996229]So I just found out about variadic parameters/templates in c++ and haven't quite figured all the ways I can use them. I want to create a templated function that will be responsible for creating an object of the templated type, but take in a variable number of arguments and supply them to the objects' constructor. Along the lines of this: [code] struct foo { foo(int a) {} }; struct bar { bar(double a, bool b, float c) {} }; template<typename T> void do_thing( ... ) { va_list args; T t = T( CONVERT ARGS INTO USEABLE ARGS ); } // Usage do_thing<foo>( 99 ); do_thing<bar>( 32.0, false, 123.456f ); [/code] Is such a thing even possible? I remember that the thread object takes in its constructor a function pointer, and a variable number of arguments, and seems to call the function with the arguments in a similar fashion.[/QUOTE] edit: updated to reflect what you want to do, i think this should work Using perfect forwarding, probably. The only relevant example I have isn't quite what you're looking for and I can't think precisely of how to do that, but it should still give you a few ideas I hope: [cpp] // templated class, with variadic template constructor template<typename T> struct do_thing { template<typename...Args> do_thing(Args&&..args) { object = { std::forward<Args>(args)... }; } T object; }; [/cpp] More thorough article: [url]http://cpptruths.blogspot.com/2012/06/perfect-forwarding-of-parameter-groups.html[/url] You can use techniques from [URL="http://aherrmann.github.io/programming/2016/02/28/unpacking-tuples-in-cpp14/"]this article[/URL] to unpack tuples, I believe, for what you want to do.
[QUOTE=paindoc;52996289]edit: updated to reflect what you want to do, i think this should work Using perfect forwarding, probably. The only relevant example I have isn't quite what you're looking for and I can't think precisely of how to do that, but it should still give you a few ideas I hope: // templated class, with variadic template constructortemplate<typename T>struct do_thing { template<typename...Args> do_thing(Args&&..args) { object = { std::forward<Args>(args)... }; } T object;}; More thorough article: [URL]http://cpptruths.blogspot.com/2012/06/perfect-forwarding-of-parameter-groups.html[/URL] You can use techniques from [URL="http://aherrmann.github.io/programming/2016/02/28/unpacking-tuples-in-cpp14/"]this article[/URL] to unpack tuples, I believe, for what you want to do.[/QUOTE] You don't need a whole new structure just to construct an object though(as it seems like that's exactly what the op wants after all, since logic is better off separated from construction). Just [code] template< typename type, typename... ctor_args > type create( ctor_args&&... args ) { return type{ std::forward< ctor_args >( args )... }; }[/code] pretty much like all those make_... work by the way.
I need help with a website. My code isn't working as intended: [URL="http://a9cleaning.co.uk/"]Here[/URL] Notice the twitter button at the top, it does not align properly with the rest of the buttons. Whenever I try and fix it, usually ends up broken? [CODE]<header> <nav> <div class='container'> <div class='five columns logo'>A9 Cleaning Services</div> <div class='eighteen columns'> <div class="top-social"> <div class="fb-like" data-href="http://www.a9cleaning.co.uk" data-layout="button_count" data-action="recommend" data-show-faces="false" data-share="true"></div> <a href="http://www.a9cleaning.co.uk" class="twitter-share-button" id="twitter" data-lang="en" data-url="http://www.a9cleaning.co.uk" data-text="Professional, affordable, discreet &amp; affordable! - A9 Cleaning Services">Tweet</a> </div> </div> </div> </nav> <div class='container'> <div class='slogan'> <div class='ten columns'> <div class=strokeme> <h2><font color="white">Professional - Affordable - Reliable</font></h2> </div> </div> </div> </header>[/CODE] Oh and btw I am quite new to CSS and PHP so please don't rip on me for my awful layout, I know it looks terrible but it "mostly" works :v:
Sorry, you need to Log In to post a reply to this thread.