C++ :: Code Review For Empty Base Optimization Pair

Apr 10, 2014

I have tried to implement a much simplified version of boost::compressed_pair.What follows is a partially specialized EBO_pair<T1, T2> class template, written in C++11.The first type T1 is constrained to not be empty.The second type T2 may or may not be empty.

#pragma once
#include <memory>
#include <type_traits>
#include <utility>
namespace dsa
}

[code]...

Edit: added non-member swap() function template.

View 10 Replies


ADVERTISEMENT

C/C++ :: Adding Base-N Through Strings (between Base-2 And Base-36)

Feb 27, 2015

I just wanted to add strings in any base form (example 1101+100 = 10001 in base-2 but it could be added using any base-form like in base-3 to base-36) and I'm having a big trouble with my code because it gave me incorrect results.

addition(char st[], char st2[], int base){
int i, j, carry = 0, ans, len, o=0, z=1, l=0;
char final[50];
if(strlen(st)>=strlen(st2))
len = strlen(st);
else
len = strlen(st2);

[Code] ....

View 1 Replies View Related

C++ :: Convert Base 10 To Base X Number Within String Of Characters

Apr 15, 2013

How would you convert say "238273615237287352536266362524382737272" base 10 to a base x number contained within a string of characters?

View 2 Replies View Related

C++ :: Compiler Optimization And Num Accuracy?

Jun 11, 2014

I could not find anything I could understand on this, so I have heard that -O3 option may reduce the numerical accuracy of doubles. Is this true?

View 11 Replies View Related

C++ :: Mixer Loop Optimization?

Nov 16, 2014

Can these loops can be optimized?

#define C_SAMPLEPOS(channel) (channel->sound.position)
#define C_BUFFERSIZE(channel) (channel->sound.numsamples)
#define C_BUFFERINC(channel) (channel->bufferinc)
//Use precalculated sample positions!

[Code]....

Should I change the inner loop (checking active channels and if they're valid) to the outer loop?

So the outer loop checks if the channel is valid for use, The inner loop checks and increases the current relsample The inner loop adds the sample to the mixer.

When the outer loop finishes: The outer loop clips all samples.

Would this be faster than the current method? (so instead of a:
for (sample=0;sample<4096;sample++){for (channel=0;channel<66;channel++){/* Process channel here */}}

We get:
for (channel=0;channel<66;channel++){for (sample=0;sample<4096;sample++){/* Process sample */}})

View 1 Replies View Related

Visual C++ :: How To Disable Optimization

Dec 27, 2014

I want to disable optimization in Visual C++ 2010. In gcc on Linux I could just use the -O0 switch, but in Visual C++ 2010 there are two categories of optimizations, one in the C/C++ pane and the other in the Linker pane:

Attachment 33229

So what settings should I choose to make sure that no optimization is being performed?

View 2 Replies View Related

C++ :: Null Statement - Prevent Optimization

Dec 7, 2014

Recently I was looking into embedded programing of AVR microcontrollers.

At this site [URL] ....

I have encounter some code that implements delay

asm volatile ("nop");

From what I understand it is assembler code that creates delay - one processor clock long.

For C/C++ language it should be like ; or {} = null statement.

Now my question is how to implement this C/C++ code and prevent my compiler (WinAVR: AVR-GCC) to delete this command during optimization (-Os or -O2). Or is it simply better to use the assembler function.

I know I can use for-loop

volatile uint8_t foo
for(foo=0; foo<2; ++foo){}

but for that I have to create a variable = wasting 1 byte of RAM; correct?

View 11 Replies View Related

C++ :: Rogue Like Item Creationg And Optimization

Mar 8, 2013

I'm creating a roguelike/ cave exploration game, and I've created a lot of it, but I am having problems with item creation. The item is supposed to be the '*'. I know what the problem is (I'm setting Dmap to map after creating the item, but before outputting Dmap), but I don't know how to fix it.Also, I don't really know how code optimization works.I'll split my code between this post and the comments:

#include <cstdlib>
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <stdio.h> /* printf, NULL */
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time *

[code].....

View 1 Replies View Related

C++ :: Binary Search Tree Optimization?

Jul 9, 2013

I was working on binary tree implementation and came up with this implementation. optimize this code?

/*
Binary Search Tree(BST)
06/27/2013
*/
#include "iostream"

[Code].....

View 3 Replies View Related

C :: Algorithm To Convert From Any Base To Base 10 Decimal

Mar 25, 2013

I got this algorithm of conversion and now I'm stuck at how to code it.

"Algorithm to Convert From any Base to Base 10 Decimal."

Let 'n' be the number of digits in the number. For example, 104 has 3 digits, so 'n'=3.
Let 'b' be the base of the number. For example, 104 is decimal so 'b' = 10.
Let 's' be a running total, initially 0.

For each digit in the number, working left to right do:

Subtract 1 from 'n'.
Multiply the digit times b^n and add it to 's'.

When done with all the digits in the number, the decimal value should be 's' .

View 6 Replies View Related

C++ :: Pair Function To Use 3 Elements?

Feb 14, 2012

is it possible to alter the Pair function to make it use 3 elements?

View 13 Replies View Related

C++ :: Metal Cutting Parameter Optimization Program

Apr 3, 2013

#include <iostream>
#include <cmath>
#include <string>
using namespace std;

[Code]....

View 3 Replies View Related

C++ :: Inserting Elements In A Set With Type Pair

Jan 8, 2013

I want to use a dataset of type set which will have the type pair<char,string> or pair<string,string>. How can i insert values into the set, because i have to initialize the set and will not change the set during the program.

View 3 Replies View Related

C++ :: How To Pair / Multimap (int Pointer To A Function)

May 22, 2012

What is the correct syntax? I tried something like

Code:
class myclass {
multimap<int, void(*)()> mm_fn;
...
void afunction();
...
void anotherfunction(int anint){
mm_fn.insert(pair<int,void(*)()>(anint,afunction));
}
}

and the compiler does not like it.

View 14 Replies View Related

C++ :: A Program To Find All Pair Of Numbers Between 0 And N That Equal K

Oct 29, 2013

int main()
{
int a=0, c, d, N, K;
bool stopBool = 0;

[Code]....

This is supposed to find take a number N and K and find all numbers between 0 and N that equal K and cout the number of pairs that fit it but it doesn't work.

View 2 Replies View Related

C++ ::  How To Print Out Elements Of Vector Of Type Pair

Oct 7, 2014

here is a piece of my code:

while(T--)
{
std::vector<std::pair<int, int> > *dragon;
std::vector<std::pair<int, int> > *villager;

[Code]....

I now wish to print the elements of the vector. How do I do it?

View 2 Replies View Related

C :: Need To Convert Base 10 Integer To Base 16

Mar 20, 2014

I need to convert an integer, for example 10, to its base 16 equivalent, 16. I found this code that converts a base 16 number to base 10, but I need the opposite. Plus, this code doesn't seem to work properly with input values under 32.

Code:

uint32_t input = 16;
uint8_t temp;
temp = ((input>>8)*100)|((input>>4)*10)|(input&0x0f);

View 13 Replies View Related

C++ :: Validity Of New / Delete Pair (or Malloc / Free) After Pointer Casting

Dec 22, 2012

Goal: To allocate some memory as a char*, read in some binary data, re-interpret it as a float* and then free the memory.

My code looks like:

void someFunction(float* &result) {
char * tmp = new char[1000];
//...Fill the char buffer here...
result = (float*)tmp; //Reinterpret binary data as floats

[Code] ....

Is the cast back to char* necessary on the red line (or could I have validly left it as float*)? Would it be different if I had written char * tmp = (char*)malloc(sizeof(char)*1000); on the blue line (and correspondingly used free (char*)floatData on the red line?

View 9 Replies View Related

C/C++ :: Delete From Sentence All Words With Character Count Which Is Equal To Pair Number

Nov 20, 2014

I have an assigment to make program which deletes from sentence all words with character count which is equal to pair number , for example - [ I like C ] and the result of this program should be [I C] because the word like contains 4 characters which is pair and it should be removed.

So I started writing my program and I am stuck at this block of code -

#include <stdio.h>
#include <stdlib.h>
main () {
char text[100], blank[100];
int c=0,d=0,i,j;
gets(text);

[Code] ....

To explain what is happening - I go through all string and search for first ' ' space symbol and check its value. If it is pair then my program prints that it is not pair[because last character before space had not pair number of characters], but the hardest part comes in when i have two not pair words , because space takes one character and now when i check if i%2 == 1 the answer is false [0] for the second word .

View 2 Replies View Related

C++ :: Converting From Base 10 To Base 4

May 7, 2013

i am converting a base 10 number to base 4.

View 1 Replies View Related

C++ :: Converting Base N To Base M

Feb 8, 2013

I was wondering if there is a standard for converting something like this:

HELLO 27 to ?3

View 5 Replies View Related

C++ :: File Created But Empty

Jul 22, 2013

A file is created but its empty. And when I first create an entry and then display all the entries, it does nothing.

#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
using namespace std;

class comp {

[Code] ....

View 2 Replies View Related

C++ :: Declaring Array To Be Empty

Jun 30, 2014

We have been assigned to create an iTunes library. Everything compiles in my other .h file but my main is not happy with my object declaration. It keeps stating "primary expression before '{'". Here is my main code:

#include<iostream>
#include<string>
#include<fstream>
#include"myTunes.h"
using namespace std;
//function protocols
void read(string);

[Code] ......

View 1 Replies View Related

C++ :: Size Of Empty Class

May 4, 2013

This code:

#include <iostream>
class Foo {
};
int main() {
Foo foo;
std::cout << sizeof ( foo ) << std::endl;
std::cin.get();
return ( 0 );
}

produces this result: 1

Why is the size of an instance of Foo 1, although it doesn't have any member variables?

View 2 Replies View Related

C++ :: Empty State Of Queue?

Feb 18, 2013

what is the empty state of queue?

View 5 Replies View Related

C++ :: How To Declare Empty Method

Oct 11, 2013

It has been a few years since I have had to do this, but I need to declare a method in my base class, but produce no code for it. Then when this library is used by my second project I will derive a class from this base class and put the code into it there. How is this possible? I used to know how but do not remember how now.

The library is a static library designed for linking with both 32bit and 64bit Windows applications to handle a lot of the tedious stuff with Windows programming. The method in question handles specific command inputs. However, since each program that uses this library will have different uses for these commands, I want to leave it up to the user to code their own handling, but require it to be coded in the derived class.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved