কম্পিউটার টিউটোরিয়াল

C++-এ is_arithmetic টেমপ্লেট

এই আর্টিকেলে আমরা C++ STL-এ std::is_arithmetic টেমপ্লেটের কাজ, সিনট্যাক্স এবং উদাহরণ নিয়ে আলোচনা করব।

is_arithmetic টেমপ্লেটটি দiber করে যে দেওয়া ক্লাস T এর ধরণ আর্থমেটিক কিনা।

আর্থমেটিক টাইপ কী?

আর্থমেটিক টাইপ দুটি ধরণের থাকে -

  • ইন্টিগ্রাল টাইপস - এখানে পূর্ণসংখ্যা ডিফাইন করা হয়। নিচে ইন্টিগ্রাল টাইপসের ধরনগুলো দেওয়া হলো -

    • char
    • bool
    • int
    • long
    • short
    • long long
    • wchar_t
    • char16_t
    • char32_t
  • ফ্লোটিং পয়েন্ট টাইপস - এগুলো ভগ্নাংশ ধারণ করতে পারে। নিচে ফ্লোটিং পয়েন্ট টাইপসের ধরনগুলো দেওয়া হলো -

    • Float
    • Double
    • Long double

সুতরাং, টেমপ্লেট is_arithmetic চেক করে যে ডিফাইন করা টাইপ T একটি আর্থমেটিক টাইপ কিনা এবং অনুযায়ী true বা false রিটার্ন করে।

সিনট্যাক্স

template <class T> is_arithmetic;

প্যারামিটারস

একটি টেমপ্লেট শুধুমাত্র একটি প্যারামিটার নিতে পারে যা টাইপ T এবং চেক করে যে প্যারামিটারটি আর্থমেটিক টাইপের কিনা।

রিটার্ন ভ্যালু

এই ফাংশন একটি বুল টাইপ মান রিটার্ন করে, যা হয় true বা false। এটি true রিটার্ন করে যদি দেওয়া টাইপ আর্থমেটিক হয় এবং false যদি টাইপ আর্থমেটিক না হয়।

উদাহরণ

Input: is_arithmetic<bool>::value; Output: True
Input: is_arithmetic<class_a>::value; Output: false

উদাহরণ

#include <iostream>
#include <type_traits>
using namespace std;

class TP { };

int main() {
    cout << boolalpha;
    cout << "checking for is_arithmetic template:";
    cout << "\nTP class : " << is_arithmetic<TP>::value;
    cout << "\n For Bool value: " << is_arithmetic<bool>::value;
    cout << "\n For long value : " << is_arithmetic<long>::value;
    cout << "\n For Short value : " << is_arithmetic<short>::value;
    return 0;
}

আউটপুট

checking for is_arithmetic template:
TP class : false
For Bool value: true
For long value : true
For Short value : true

উদাহরণ

#include <iostream>
#include <type_traits>
using namespace std;

int main() {
    cout << boolalpha;
    cout << "checking for is_arithmetic template:";
    cout << "\nInt : " << is_arithmetic<int>::value;
    cout << "\nchar : " << is_arithmetic<char>::value;
    cout << "\nFloat : " << is_arithmetic<float>::value;
    cout << "\nDouble : " << is_arithmetic<double>::value;
    cout << "\nInt *: " << is_arithmetic<int*>::value;
    cout << "\nchar *: " << is_arithmetic<char*>::value;
    cout << "\nFloat *: " << is_arithmetic<float*>::value;
    cout << "\nDouble *: " << is_arithmetic<double*>::value;
    return 0;
}

আউটপুট

checking for is_arithmetic template:
Int : true
Char : true
Float : true
Double : true
Int * : float
Char *: float
Float *: float
Double *: float
  1. C++-এ টেমপ্লেট মেটাপ্রোগ্রামিং

  2. C++-এ fabs() ফাংশন

  3. C++-এ expm1() ফাংশন

  4. C++-এ log1p() ফাংশন