Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7401163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:23:43+00:00 2026-05-29T04:23:43+00:00

I am writing a library for efficient number processing. I have to support different

  • 0

I am writing a library for efficient number processing. I have to support different types of numbers — double, complex, or even custom_matrix maybe. For performance reasons I’ve decided to compile separate library file for each number kind, so that compiler may use aggressive optimizations for arithmetic operations and function calls. Now I have two options — either to write template classes with parameter number_type, e.g.

template <typename valueType>
class Worker {
    valueType process(valueType value);
};

or to typedef number kind in project-wide header file, e.g.

in 'project.hpp':

namespace myProject {
    typedef double valueType;
}

in 'worker.hpp':

#include "project.hpp"

namespace myProject {
    class Worker {
        valueType process(valueType value);
    };
}

Personally I can’t accept either way: template-based code is driving me insane with tons of redundant template and typename keywords, meanwhile typedef-based code can’t be compiled in single library file (linking fails because of duplicate names), so I can’t use different number types in one program.

So the question is: am I missing something? Is there a better/cleaner way to accomplish my task?

EDIT: I have to use double and complex code in one application at the same time.

EDIT2: Okay, to make things clear: I’m developing an arithmetic expression parsing engine for iOS app. Therefore I’m limited to C/C++/Objective-C, and the performance is crucial.

Also, I feel comfortable in using templates in common circumstances. In my situation all my source files are full of angle brackets and template/typename keywords. It’s simply annoying and distracts me from writing stuff that matters.

I guess I’ll use templates, since there is no better solution as far as I can see.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:23:44+00:00Added an answer on May 29, 2026 at 4:23 am

    You should use the templates. If you insist on doing the absolute maximum amount of work at compile time instead of at run time, and your language of choice is C++, you will use template programming.

    It’s a mess of less-than and greater-than signs, confusing error messages, and typename keywords (plus don’t get me started on explicit instantiations when you don’t want to define your whole class in the header!), but it’s the mess we’ve got.

    EDIT: there is a third option, in the form of preprocessing – you could run the same code through the preprocessor twice, putting the symbols in a different namespace each time, to get the same effect as the typedef version without the symbol collisions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a bignum library, and I want to use efficient data types to
I'm learning C# by writing a home library manager. I have a BookController that
I'm writing a .NET 4.0 library that should be efficient and simple to use.
I am writing a library in VB.NET in which I have added, among others,
I am writing a library for CI and I have a method I call
I'm writing a library for parsing expressions into a tree structure and I have
I am writing a library in C++ and have some functions that work with
I am writing a library in standard C++ which does the phonetic conversion. I
I am writing a library which uses a few functions from the windows user32.dll
Say that you're writing a library to display things on the screen, so you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.