C++ :: Obtaining Operator From Compile-time Constant?
Nov 5, 2014
I want to generalize my productFunction below to a template family of functions where the template merely changes the * to + or whatever else operator I wish to use.
#include <iostream>
#include <functional>
#define show(variable) std::cout << #variable << " = " << variable << std::endl;
template <typename, typename...> struct ProductFunction;
template <typename RETURN_TYPE, typename FIRST, typename... REST>
struct ProductFunction<RETURN_TYPE, FIRST, REST...> : ProductFunction<RETURN_TYPE, REST...> {
const FIRST function;
using Base = ProductFunction<RETURN_TYPE, REST...>;
[code].....
How can I turn a template parameter into various operators? (apart from using switch statements that will reduce the performance and make the code really ugly) What kind of metatemplating method converts a compile-time constant to an operator?
View 3 Replies
ADVERTISEMENT
Jun 13, 2013
I'm looking for a function like GetThreadTimes, but one that gives correct results in a hyperthreading CPU.
For instance, if you start 2 threads on a CPU with 1 physical core and 2 logical cores, GetThreadTimes will say that both these threads use 100% CPU.
However, in reality they only use 50% each. Is there a function that returns correct results, or is there another workaround?
View 8 Replies
View Related
May 13, 2013
Is there any possible way of calculating some values at compile time? I have the following code of genereting upto 2000000010 palindrome numbers.
Code:
#include <iostream>
#include <string>
#include <sstream>
#include <string.h>
#include <stdlib.h>
[Code] .....
As you see, I have taken input from the user just after calculating the whole palindromes. So cant we calculate this at compile time? because runtime of this program is extremely slow.
Another qs. I first tried to use array but It didnt allow 2*10^9 sized array. so what should I do whenever I need that size of array?
View 12 Replies
View Related
Sep 1, 2013
My question is this: Is it possible to determine where functions are stored at compile time, so that at run time you can pass the memory address as a pointer to the interrupt handler so that it can directly call the function at memory location 'X'?
The newest project I'm working on would require to either somehow capture these addresses or to find a work-around so that instead of passing the pointer to the interrupt handler, the software would then need to be able to be non-interruptable.
View 2 Replies
View Related
Jan 18, 2012
Would there be anyway for the compiler, or the language, to provide a unique ID during compilation?
I've been using UUID generators, but I've always found the approach of copy pasting from a program to code to be kind of... limiting. If I want a random number, can't the compiler guarantee this for me?
It already does the same thing for anonymous namespaces, so...
View 6 Replies
View Related
Apr 10, 2013
Consider:
Code: template<unsigned int N>
class Test
{
private:
[Code]....
I just cannot understand why (clearly, we are calling <0, 0>, not <0, 8>). If I replace "N" with 8, it works as expected (at least for the beginning of the loop). I only tested on MSVC.
View 5 Replies
View Related
Mar 6, 2013
I am working on a project, where I have to be able to exclude some code fast and dynamicly at compiletime.
I got a scheduler running and actually I just want to remove some of the tasks from it - but at compile time so that the code wont take up space in my microcontroller.
I know that I can use macros like #ifdef #endif etc. But I think that method makes the code unreadable and complicated.
How to archive such functionality a more elegant way?
View 1 Replies
View Related
Nov 19, 2013
So I made a library for a whole bunch of functions and when i compile it, it says"Unresolved external symbol_(Name of function here) referenced in function main.
View 1 Replies
View Related
Mar 28, 2014
I would like to have a program with a 5 mb string embedded in it kind of like this:
Code:
const char *c;
c = (const char*)"BEGIN_STRING_HERE, (5 MB of arbitrary values here)";
Is it possible to generate this string at compile time? Maybe with a macro? I'm trying to avoid a source file with a 5 mb string in it.
View 3 Replies
View Related
Oct 22, 2013
How do I set the size of a member array via the class constructor if I know the size at compile time. I can do this with templates, see below, but this leads to code bloats, I think.
So one class declaration but objects with different array sizes.
Can't use constexpr.
Can't use STL.
Can't use new.
#include <iostream>
using namespace std;
template<int T>
class MyArray {
private:
int array[T];
public:
int getSize()
[Code] ....
View 15 Replies
View Related
Feb 4, 2014
I am trying to build a VC++ project in Visual Studio 2010. [URL] ....
This project has a dependency on openssl libraries. How can I successfully build this project? How to add third party libs/dlls in a project.
View 1 Replies
View Related
Mar 6, 2015
Code:
typedef struct token
{
int tokenType; // what token is that
int tokenCode; // the code of a function if applicable
char *tokenString; // Source token
double tokenValue; // if token is a number
[Code] .....
I got several warnings and erros, is it possible to declare a table like that ? What's the correct way to declare it ?
View 4 Replies
View Related
Feb 18, 2015
I am creating a class called time and we've had to do operator overloading for <, > , <=, >=, ==, !=, ++, --, >>, <<, * , +, and -.
Well I have done and error checked them all. The only one I cannot seem to get right is the minus and its because of the error checking. I am having issues with times like this
t1 = 0:0:2:3
t2 = 0:0:1:4
t1 - t2 should equal 0:0:0:59 but it returns 0:0:1:-1.
(days:hours:minutes:seconds)
I need it to check for all cases and I just do not know how. Here is the code I have so far:
time operator- (const time& x, const time& y){
time subtract;
subtract.days = x.days - y.days;
subtract.hrs = x.hrs - y.hrs;
subtract.mins = x.mins - y.mins;
subtract.secs = x.secs - y.secs;
[Code] .....
View 1 Replies
View Related
Feb 28, 2013
I'm writing a program where a user keeps entering numbers until "0" is entered.Once "0" is entered the loop ends and It displays the mean. Problem is it counts the "0" in the average.
e,g:
Enter number 1: 5
Enter number 2: 2
Enter number 3: 3
Enter number 4: 0
The mean is 2.5. But I want it to only count everything before the "0". (5 + 2 + 3) / 3 = 3.333333
View 3 Replies
View Related
Aug 24, 2014
My program has a large version of this, where every leaf class is singleton, and pointers of the base class to represent each possible path are stored in a map during compile time. I have it working as follows:
#include <iostream>
#include <string>
#include <map>
[Code].....
But System::initializePrototypes() is constructing the map manually, and I want to use recursion somehow, because my hierarchy is much bigger than this. It's also easy to miss a path doing it the above way, and when new classes are added to the hierarchy, it will be a nightmare to update the map. So the ideal solution is recursion constructing the map perfectly--and when new classes are introduced, nothing needs to be added to System::initializePrototypes().
View 7 Replies
View Related
Feb 20, 2015
Can distinguish between character constant and string constant giving examples
View 1 Replies
View Related
Aug 28, 2012
I am trying to obtain the values of cookies from a particular website. The problem is, when I run the following code, it only loops through 4 of 10 cookie values present.
Furthermore, the values are turning up as deleted: Reference
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("http://www.mysite.com");
Request.CookieContainer = new CookieContainer();
HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
foreach (Cookie cook in Response.Cookies) {
Console.WriteLine("{0} = {1}", cook.Name, cook.Value);
}
Then I came across this code, which states it will loop through every cookie value and obtain its values: Reference
int loop1, loop2;
HttpCookieCollection MyCookieColl;
HttpCookie MyCookie;
MyCookieColl = Request.Cookies;
String[] arr1 = MyCookieColl.AllKeys;
for (loop1 = 0; loop1 < arr1.Length; loop1++) {
MyCookie = MyCookieColl[arr1[loop1]];
String[] arr2 = MyCookie.Values.AllKeys;
}
The problem with the above, I can't seem to find a reference to "Request". I am using the libraries "using System.Net and using System.Web", so I am unsure why Request is not being recognized.
My goal is to retrieve one cookie value so that when a user from my website logs in, my C# application will recognize that user.
View 7 Replies
View Related
Mar 22, 2013
I'm doing a refresher for C++ and have gotten to operator overloading. I'm trying to perform an operator overload with the insertion (<<) operator, but I have encountered a problem.
Here's my class [In a header file "Shinigami.h"]
#include<string>
namespace K{
class Quincy;
class Shinigami{
friend std::ostream& operator<<(std::ostream&, const Shinigami&);
[Code] .....
If the operator function is a friend of the 'Shinigami' class, why doesn't it recognize any of it's private members? I need it to be in this file because I'm doing a bit of association with the 'Quincy' class.
I thought it was the namespace, but I included that.
View 9 Replies
View Related
Mar 10, 2015
This is a round robin execution. with gantt chart. arrival time and burst time. I think there is an error in my formula to get the right answer,i cant resolve it but my program is running. What is the code or the right formula??
#include<stdio.h>
int main(){
int i,j=0,n,time,remain,flag=0,ts;
int sum_wait=0,sum_turnaround=0,at[10],bt[10],rt[10];
int ganttP[50],ganttStartTime[50];
printf("Enter no of Processes : ");
scanf("%d",&n);
remain=n;
[Code] ....
View 2 Replies
View Related
Dec 28, 2012
#include <iostream>
class Hello {
public:
void Test() {
[Code].....
As i know a non-constant member function cant be called inside a constant member function but how the above code has been compiled successfully and giving the expected result .
View 5 Replies
View Related
May 1, 2013
So I'm trying to learn how to use time for time based movement and what not. I did this only knowing the command time(&variable)
time_t timer;
int I, X;
void main() {
time(&timer);
X=timer;
while(I==5) {
[Code] ......
There's probably some other better way to do it... Obviously but for now I see it as putting current time in X.
start while
take in time constantly until I is 5
constantly asking is time>X(preset time 5 seconds ahead)
if it is
display message and add one to I
Why doesn't this display my message after 5 seconds?
View 1 Replies
View Related
Mar 18, 2013
make a time-in time-out fuction which extracts the no. of hours and minutes from a string entered by the user.
#include <iostream>
#include <fstream>
#include <string>
[Code].....
View 3 Replies
View Related
Mar 6, 2014
when we would use add items at design time and when we would add them at run time
does it have anything to do with the page load method? if so, can i type this in source code instead?
View 2 Replies
View Related
Aug 3, 2012
This is the first time I'm trying to program in C# and I'm having some trouble.I can't find a way to compile whatever I do.I don't think it's a problem of what I wrote but I might not have what is necessary.I tried: C:>csc fisrt.cs csc was not a valid command.
View 1 Replies
View Related
Oct 23, 2013
line 27 and line 88 Im having a hard time figuring it out what the error is.
#include<iostream>
#include <cmath>
#include<algorithm>
[Code]....
View 2 Replies
View Related
Oct 4, 2014
I have 2 c++ source files to put into my eclipse project and also a header file. How do I compile all of it to make an .exe file?
View 18 Replies
View Related